<?php

declare(strict_types=1);

namespace ImovelZapAi\ClientPortal\Infrastructure\Persistence\Eloquent;

use Database\Factories\DocumentRequestFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

class DocumentRequestModel extends Model
{
    use BelongsToTenant;
    use HasFactory;
    use HasUuidPrimaryKey;

    protected $table = 'document_requests';

    protected $fillable = [
        'tenant_id', 'client_portal_id', 'status', 'notes',
    ];

    protected static function newFactory(): DocumentRequestFactory
    {
        return DocumentRequestFactory::new();
    }

    public function portal(): BelongsTo
    {
        return $this->belongsTo(ClientPortalModel::class, 'client_portal_id');
    }

    public function documents(): HasMany
    {
        return $this->hasMany(RequestedDocumentModel::class, 'document_request_id')->orderBy('position');
    }
}
