<?php

declare(strict_types=1);

namespace ImovelZapAi\Importing\Infrastructure\Persistence\Eloquent;

use Database\Factories\PropertyImportSourceFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use ImovelZapAi\Properties\Infrastructure\Persistence\Eloquent\PropertyModel;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

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

    protected $table = 'property_import_sources';

    protected $fillable = [
        'tenant_id',
        'property_id',
        'source',
        'external_id',
        'payload_hash',
        'last_seen_at',
    ];

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

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

    public function property(): BelongsTo
    {
        return $this->belongsTo(PropertyModel::class, 'property_id');
    }
}
