<?php

namespace App\Models;

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

/** @property array<string,mixed>|null $permissions */
class EventMember extends Model
{
    /** @use HasFactory<\Database\Factories\EventMemberFactory> */
    use HasFactory;

    protected $fillable = [
        'tenant_id',
        'event_id',
        'user_id',
        'invited_by',
        'name',
        'email',
        'role',
        'status',
        'invite_token',
        'invited_at',
        'joined_at',
        'last_activity_at',
        'permissions',
    ];

    protected $casts = [
        'invited_at' => 'datetime',
        'joined_at' => 'datetime',
        'last_activity_at' => 'datetime',
        'permissions' => 'array',
    ];

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

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

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

    public function invitedBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'invited_by');
    }
}
