<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\Shift;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Shift>
 */
class ShiftFactory extends Factory
{
    protected $model = Shift::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $code = fake()->randomElement(['A', 'B', 'C', 'Night']);
        $times = match ($code) {
            'A' => ['starts_at' => '06:00:00', 'ends_at' => '14:00:00'],
            'B' => ['starts_at' => '14:00:00', 'ends_at' => '22:00:00'],
            'C' => ['starts_at' => '22:00:00', 'ends_at' => '06:00:00'],
            default => ['starts_at' => '22:00:00', 'ends_at' => '06:00:00'],
        };

        $name = match ($code) {
            'A' => 'Morning Shift',
            'B' => 'Afternoon Shift',
            'C' => 'Evening Shift',
            default => 'Night Shift',
        };

        return [
            'name' => $name,
            'code' => Shift::generateUniqueCodeFromName($name),
            'starts_at' => $times['starts_at'],
            'ends_at' => $times['ends_at'],
            'description' => fake()->optional()->sentence(),
            'is_active' => true,
        ];
    }

    public function shiftA(): static
    {
        return $this->state(fn (array $attributes): array => [
            'name' => 'Shift A',
            'code' => 'A',
            'starts_at' => '06:00:00',
            'ends_at' => '14:00:00',
        ]);
    }

    public function shiftB(): static
    {
        return $this->state(fn (array $attributes): array => [
            'name' => 'Shift B',
            'code' => 'B',
            'starts_at' => '14:00:00',
            'ends_at' => '22:00:00',
        ]);
    }

    public function shiftC(): static
    {
        return $this->state(fn (array $attributes): array => [
            'name' => 'Shift C',
            'code' => 'C',
            'starts_at' => '22:00:00',
            'ends_at' => '06:00:00',
        ]);
    }

    public function night(): static
    {
        return $this->state(fn (array $attributes): array => [
            'name' => 'Night Shift',
            'code' => 'Night',
            'starts_at' => '22:00:00',
            'ends_at' => '06:00:00',
        ]);
    }
}
