<?php

namespace Database\Factories;

use App\Modules\Catalog\Models\Product;
use App\Modules\Promotions\Models\FlashSale;
use Illuminate\Database\Eloquent\Factories\Factory;

class FlashSaleFactory extends Factory
{
    protected $model = FlashSale::class;

    public function definition(): array
    {
        return [
            'name'           => fake()->words(3, true) . ' Flash Sale',
            'vendor_id'      => null,
            'product_id'     => Product::factory(),
            'product_variant_id' => null,
            'discount_type'  => fake()->randomElement(['flat', 'percent']),
            'discount_value' => fake()->randomFloat(2, 5, 50),
            'sale_price'     => null,
            'max_qty'        => fake()->optional(0.5)->numberBetween(5, 100),
            'sold_qty'       => 0,
            'starts_at'      => now()->subHour(),
            'ends_at'        => now()->addHours(24),
            'is_active'      => true,
        ];
    }

    public function active(): static
    {
        return $this->state([
            'is_active' => true,
            'starts_at' => now()->subHour(),
            'ends_at'   => now()->addHour(),
        ]);
    }

    public function inactive(): static
    {
        return $this->state(['is_active' => false]);
    }

    public function expired(): static
    {
        return $this->state([
            'starts_at' => now()->subDay(),
            'ends_at'   => now()->subHour(),
        ]);
    }

    public function percent(float $value = 20): static
    {
        return $this->state([
            'discount_type'  => 'percent',
            'discount_value' => $value,
        ]);
    }

    public function flat(float $value = 100): static
    {
        return $this->state([
            'discount_type'  => 'flat',
            'discount_value' => $value,
        ]);
    }
}
