<?php

namespace Database\Seeders;

use App\Enums\VoucherType;
use App\Models\Outlet;
use App\Models\Voucher;
use Illuminate\Database\Seeder;

class VoucherSeeder extends Seeder
{
    public function run(): void
    {
        $vouchers = [
            [
                'name' => 'Diskon 10%',
                'code' => 'DISC10',
                'type' => VoucherType::PERCENTAGE,
                'discount_amount' => 10,
                'min_purchase' => 50000,
                'max_discount' => 20000,
                'quota' => 100,
                'available_count' => 100,
                'limit_per_user' => 2,
                'start_date' => now()->subDays(5),
                'end_date' => now()->addMonth(),
            ],
            [
                'name' => 'Diskon 20%',
                'code' => 'DISC20',
                'type' => VoucherType::PERCENTAGE,
                'discount_amount' => 20,
                'min_purchase' => 100000,
                'max_discount' => 50000,
                'quota' => 50,
                'available_count' => 50,
                'limit_per_user' => 1,
                'start_date' => now(),
                'end_date' => now()->addDays(30),
            ],
            [
                'name' => 'Potongan Rp25K',
                'code' => 'SAVE25K',
                'type' => VoucherType::FIXED,
                'discount_amount' => 25000,
                'min_purchase' => 100000,
                'max_discount' => null,
                'quota' => 200,
                'available_count' => 200,
                'limit_per_user' => 3,
                'start_date' => now(),
                'end_date' => now()->addDays(15),
            ],
            [
                'name' => 'Potongan Rp50K',
                'code' => 'SAVE50K',
                'type' => VoucherType::FIXED,
                'discount_amount' => 50000,
                'min_purchase' => 200000,
                'max_discount' => null,
                'quota' => 80,
                'available_count' => 80,
                'limit_per_user' => 1,
                'start_date' => now()->addDays(3),
                'end_date' => now()->addDays(60),
            ],
            [
                'name' => 'Gratis Ongkir',
                'code' => 'ONGKIR',
                'type' => VoucherType::FIXED,
                'discount_amount' => 15000,
                'min_purchase' => 50000,
                'max_discount' => 15000,
                'quota' => 500,
                'available_count' => 500,
                'limit_per_user' => 5,
                'start_date' => now(),
                'end_date' => now()->addDays(90),
            ],
            [
                'name' => 'Flash Sale 30%',
                'code' => 'FLASH30',
                'type' => VoucherType::PERCENTAGE,
                'discount_amount' => 30,
                'min_purchase' => 75000,
                'max_discount' => 40000,
                'quota' => 30,
                'available_count' => 30,
                'limit_per_user' => 1,
                'start_date' => now()->subDay(),
                'end_date' => now()->addDay(),
            ],
            [
                'name' => 'Spesial Member',
                'code' => 'MEMBER15',
                'type' => VoucherType::PERCENTAGE,
                'discount_amount' => 15,
                'min_purchase' => 50000,
                'max_discount' => 25000,
                'quota' => null,
                'available_count' => null,
                'limit_per_user' => null,
                'start_date' => now(),
                'end_date' => null,
            ],
        ];

        foreach ($vouchers as $voucher) {
            $newVoucher = Voucher::create($voucher);

            $newVoucher->outlets()->attach(Outlet::inRandomOrder()->first()->id);
        }
    }
}
