<?php

namespace App\Models;

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

/**
 * @property int         $id
 * @property int         $conversation_id
 * @property int         $user_id
 * @property string      $role           member|admin
 * @property \Carbon\Carbon|null $last_read_at
 * @property bool        $is_muted
 * @property bool        $is_archived
 * @property bool        $is_pinned
 * @property \Carbon\Carbon|null $pinned_at
 * @property \Carbon\Carbon $joined_at
 * @property \Carbon\Carbon|null $left_at
 */
class ConversationParticipant extends Model
{
    use HasFactory;

    public $timestamps = false;

    protected $fillable = [
        'conversation_id',
        'user_id',
        'role',
        'last_read_at',
        'last_read_message_id',
        'is_muted',
        'is_archived',
        'is_pinned',
        'is_hidden',
        'pinned_at',
        'joined_at',
        'left_at',
    ];

    protected $casts = [
        'last_read_at' => 'datetime',
        'last_read_message_id' => 'integer',
        'is_muted'     => 'boolean',
        'is_archived'  => 'boolean',
        'is_pinned'    => 'boolean',
        'is_hidden'    => 'boolean',
        'pinned_at'    => 'datetime',
        'joined_at'    => 'datetime',
        'left_at'      => 'datetime',
    ];

    // ── Relationships ────────────────────────────────────────────────────────

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

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