<?php

namespace App\Models;

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

class ChatMessage extends Model
{
    protected $fillable = [
        'caso_id',
        'user_id',
        'ajustador_id',
        'message',
    ];

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

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

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

    public function senderName(): string
    {
        if ($this->user) {
            return $this->user->name;
        }
        if ($this->ajustador) {
            return $this->ajustador->nombre;
        }

        return 'Desconocido';
    }

    public function senderIsAdmin(): bool
    {
        return $this->user_id !== null;
    }

    public function senderIsAdjuster(): bool
    {
        return $this->ajustador_id !== null;
    }
}
