<?php
namespace Database\Factories;

use App\Models\Candidat;
use App\Enums\TypeDocument;
use Illuminate\Database\Eloquent\Factories\Factory;

class PieceJointeFactory extends Factory
{
    public function definition(): array
    {
        $type = fake()->randomElement(TypeDocument::cases());
        return [
            'candidat_id'          => Candidat::factory(),
            'type_document'        => $type->value,
            'nom_fichier_original' => fake()->word() . '.pdf',
            'chemin_stockage'      => "candidats/1/{$type->value}/" . fake()->uuid() . '.pdf',
            'mime_type'            => 'application/pdf',
            'taille_octets'        => fake()->numberBetween(50000, 5000000),
            'statut_validation'    => 'en_attente',
            'commentaire_rejet'    => null,
            'date_expiration'      => null,
            'valide_par'           => null,
            'valide_at'            => null,
        ];
    }

    public function valide(): static
    {
        return $this->state(fn() => ['statut_validation' => 'valide']);
    }

    public function rejete(): static
    {
        return $this->state(fn() => [
            'statut_validation' => 'rejete',
            'commentaire_rejet' => 'Document illisible, veuillez soumettre un scan de meilleure qualité.',
        ]);
    }

    public function casierJudiciaire(): static
    {
        return $this->state(fn() => [
            'type_document'  => TypeDocument::CASIER_JUDICIAIRE->value,
            'date_expiration' => now()->addMonths(3)->toDateString(),
        ]);
    }

    public function forCandidat(Candidat $candidat): static
    {
        return $this->state(fn (array $attributes) => [
            'candidat_id' => $candidat->id,
        ]);
    }
}
