<?php

declare(strict_types=1);

namespace ImovelZapAi\Financial\Infrastructure\Persistence\Eloquent;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use ImovelZapAi\ClientPortal\Infrastructure\Persistence\Eloquent\ClientPortalModel;
use ImovelZapAi\Documents\Infrastructure\Persistence\Eloquent\BusinessDocumentModel;
use ImovelZapAi\Sales\Infrastructure\Persistence\Eloquent\DealModel;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

class FinancialReceiptModel extends Model
{
    use BelongsToTenant;
    use HasUuidPrimaryKey;

    protected $table = 'financial_receipts';

    protected $fillable = [
        'tenant_id',
        'deal_id',
        'payment_id',
        'number',
        'issued_at',
        'client_portal_id',
        'business_document_id',
        'notes',
    ];

    protected function casts(): array
    {
        return [
            'issued_at' => 'datetime',
        ];
    }

    public function deal(): BelongsTo
    {
        return $this->belongsTo(DealModel::class, 'deal_id');
    }

    public function payment(): BelongsTo
    {
        return $this->belongsTo(FinancialPaymentModel::class, 'payment_id');
    }

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

    public function businessDocument(): BelongsTo
    {
        return $this->belongsTo(BusinessDocumentModel::class, 'business_document_id');
    }
}
