<?php

declare(strict_types=1);

namespace ImovelZapAi\Documents\Infrastructure\Persistence\Eloquent;

use Database\Factories\DocumentTemplateFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use ImovelZapAi\Documents\Domain\Enums\DocumentType;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

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

    protected $table = 'studio_document_templates';

    protected $fillable = [
        'tenant_id', 'name', 'document_type', 'body_html', 'body_json',
        'is_default', 'is_system', 'created_by',
    ];

    protected function casts(): array
    {
        return [
            'document_type' => DocumentType::class,
            'body_json' => 'array',
            'is_default' => 'boolean',
            'is_system' => 'boolean',
        ];
    }

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

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