<?php

namespace App\Models;

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

class EventJoinTokenEvent extends Model
{
    use HasFactory;

    protected $fillable = [
        'event_join_token_id',
        'event_id',
        'tenant_id',
        'token_hash',
        'token_preview',
        'event_type',
        'route',
        'http_method',
        'http_status',
        'device_id',
        'ip_address',
        'user_agent',
        'context',
        'occurred_at',
    ];

    protected $casts = [
        'context' => 'array',
        'occurred_at' => 'datetime',
    ];

    public function joinToken(): BelongsTo
    {
        return $this->belongsTo(EventJoinToken::class, 'event_join_token_id');
    }

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

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

