<?php

declare(strict_types=1);

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use ImovelZapAi\ClientPortal\Infrastructure\Persistence\Eloquent\ClientPortalModel;
use ImovelZapAi\ClientPortal\Infrastructure\Persistence\Eloquent\PortalAccessTokenModel;
use ImovelZapAi\Tenancy\Infrastructure\Persistence\Eloquent\TenantModel;

/** @extends Factory<PortalAccessTokenModel> */
class PortalAccessTokenFactory extends Factory
{
    protected $model = PortalAccessTokenModel::class;

    public function definition(): array
    {
        $plain = Str::lower(Str::random(40));
        $portal = ClientPortalModel::factory();

        return [
            'tenant_id' => TenantModel::factory(),
            'client_portal_id' => $portal,
            'token_prefix' => substr($plain, 0, 8),
            'token_hash' => hash('sha256', $plain),
            'signature' => 'pending',
            'expires_at' => now()->addDays(14),
        ];
    }
}
