<?php

declare(strict_types=1);

namespace ImovelZapAi\Sales\Infrastructure\Persistence\Eloquent;

use App\Models\User;
use Database\Factories\DealActivityFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use ImovelZapAi\Sales\Domain\Enums\DealActivityType;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

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

    protected $table = 'sales_deal_activities';

    protected $fillable = [
        'tenant_id',
        'deal_id',
        'actor_user_id',
        'type',
        'title',
        'body',
        'meta',
        'occurred_at',
    ];

    protected function casts(): array
    {
        return [
            'type' => DealActivityType::class,
            'meta' => 'array',
            'occurred_at' => 'datetime',
        ];
    }

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

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

    public function actor(): BelongsTo
    {
        return $this->belongsTo(User::class, 'actor_user_id');
    }
}
