<?php

namespace Database\Factories;

use App\Domain\Agents\Enums\AgentStatus;
use App\Domain\Organization\Models\Company;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class AgentFactory extends Factory
{
    public function definition(): array
    {
        return [
            'agent_code' => 'AGT-TST-'.Str::padLeft((string) $this->faker->unique()->numberBetween(1, 999999), 6, '0'),
            'company_id' => Company::factory(),
            'name' => $this->faker->name(),
            'phone' => $this->faker->unique()->numerify('01#########'),
            'email' => $this->faker->unique()->safeEmail(),
            'agent_type' => 'external',
            'status' => AgentStatus::PendingApproval->value,
            'territory' => $this->faker->city(),
        ];
    }

    public function status(AgentStatus $status): static
    {
        return $this->state(fn () => [
            'status' => $status->value,
            'approved_at' => $status === AgentStatus::Active ? now() : null,
        ]);
    }

    public function active(): static
    {
        return $this->status(AgentStatus::Active);
    }
}
