<?php

declare(strict_types=1);

namespace ImovelZapAi\Proposals\Infrastructure\Persistence\Eloquent;

use Database\Factories\ProposalTemplateFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use ImovelZapAi\Proposals\Domain\Enums\ProposalPurpose;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

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

    protected $table = 'proposal_templates';

    protected $fillable = [
        'tenant_id', 'name', 'purpose', 'body_html', 'is_default', 'created_by',
    ];

    protected function casts(): array
    {
        return [
            'purpose' => ProposalPurpose::class,
            'is_default' => 'boolean',
        ];
    }

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

    public function proposals(): HasMany
    {
        return $this->hasMany(ProposalModel::class, 'template_id');
    }
}
