<?php

declare(strict_types=1);

namespace ImovelZapAi\Proposals\Infrastructure\Persistence\Eloquent;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\BelongsToTenant;
use ImovelZapAi\Shared\Infrastructure\Persistence\Concerns\HasUuidPrimaryKey;

class ProposalViewModel extends Model
{
    use BelongsToTenant;
    use HasUuidPrimaryKey;

    protected $table = 'proposal_views';

    protected $fillable = [
        'tenant_id', 'proposal_id', 'proposal_share_id', 'proposal_version_id',
        'ip', 'user_agent', 'device', 'started_at', 'ended_at', 'duration_seconds',
    ];

    protected function casts(): array
    {
        return [
            'started_at' => 'datetime',
            'ended_at' => 'datetime',
            'duration_seconds' => 'integer',
        ];
    }

    public function proposal(): BelongsTo
    {
        return $this->belongsTo(ProposalModel::class, 'proposal_id');
    }
}
