<?php

namespace Database\Seeders;

use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class CouponsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        foreach (range(1, 15) as $index) {
            $start_date = Carbon::now()->subDays(rand(1, 7))->toDateString();

            $end_date = Carbon::parse($start_date)->addDays(7)->toDateString();

            DB::table('coupons')->insert([
                'name' => Str::title(Str::random(6)) . ' Discount',
                'code' => strtoupper(Str::random(6) . rand(100, 999)),
                'type' => rand(1, 2),
                'amount' => rand(5 * 100, 100 * 100) / 100,
                'start_date' => $start_date,
                'end_date' => $end_date,
                'min_amount' => rand(10 * 100, 100 * 100) / 100,
                'max_uses' => rand(10, 20),
                'use_once' => rand(0, 1),
                'on_subtotal' => rand(0, 1),
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ]);
        }
    }
}
