<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class WorldAnalyticsEvent extends Model
{
    use HasFactory;

    public $timestamps = false;

    const CREATED_AT = 'occurred_at';
    const UPDATED_AT = null;

    protected $fillable = [
        'world_id',
        'event_type',
        'world_slug',
        'world_type',
        'recurrence_key',
        'edition_year',
        'section_key',
        'cta_key',
        'entity_type',
        'entity_id',
        'entity_title',
        'challenge_id',
        'source_surface',
        'source_detail',
        'viewer_type',
        'user_id',
        'visitor_key',
        'meta',
        'occurred_at',
    ];

    protected function casts(): array
    {
        return [
            'world_id' => 'integer',
            'edition_year' => 'integer',
            'entity_id' => 'integer',
            'challenge_id' => 'integer',
            'user_id' => 'integer',
            'meta' => 'array',
            'occurred_at' => 'datetime',
        ];
    }

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

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