<?php

declare(strict_types=1);

namespace ImovelZapAi\Analytics\Infrastructure\Persistence\Eloquent;

use App\Models\User;
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 AnalyticsFactModel extends Model
{
    use BelongsToTenant;
    use HasUuidPrimaryKey;

    public $timestamps = false;

    protected $table = 'analytics_facts';

    protected $fillable = [
        'tenant_id',
        'event_key',
        'occurred_at',
        'entity_type',
        'entity_id',
        'user_id',
        'amount',
        'meta',
        'created_at',
    ];

    protected function casts(): array
    {
        return [
            'occurred_at' => 'datetime',
            'amount' => 'decimal:2',
            'meta' => 'array',
            'created_at' => 'datetime',
        ];
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}
