<?php

declare(strict_types=1);

namespace ImovelZapAi\ClientPortal\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 PortalSessionModel extends Model
{
    use BelongsToTenant;
    use HasUuidPrimaryKey;

    protected $table = 'portal_sessions';

    protected $fillable = [
        'tenant_id', 'client_portal_id', 'portal_access_token_id',
        'ip', 'user_agent', 'started_at', 'last_seen_at',
    ];

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

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