<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\SupportTicket;
use App\Models\TicketReply;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TicketReply>
 */
class TicketReplyFactory extends Factory
{
    protected $model = TicketReply::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'ticket_id' => SupportTicket::factory(),
            'user_id' => User::factory(),
            'body' => fake()->paragraphs(2, true),
            'is_staff_reply' => false,
            'message_id' => null,
            'from_email' => null,
            'via_email' => false,
        ];
    }

    public function staffReply(): static
    {
        return $this->state(fn (array $attributes): array => [
            'is_staff_reply' => true,
        ]);
    }

    public function viaEmail(?string $fromEmail = null): static
    {
        return $this->state(fn (array $attributes): array => [
            'via_email' => true,
            'from_email' => $fromEmail ?? fake()->safeEmail(),
            'message_id' => '<'.fake()->uuid().'@example.com>',
        ]);
    }
}
