<?php

namespace App\Models;

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

class Message extends Model
{
    use HasFactory;

    protected $fillable = [
        'conversation_id', 'user_id', 'direction', 'type',
        'content', 'media_url', 'media_filename', 'wa_message_id', 'status',
    ];

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

    public function isIncoming(): bool
    {
        return $this->direction === 'incoming';
    }

    public function isMedia(): bool
    {
        return in_array($this->type, ['image', 'audio', 'video', 'document', 'sticker']);
    }

    /**
     * Human-readable media type label for the chat preview.
     */
    public function mediaLabel(): string
    {
        return match ($this->type) {
            'image'    => '📷 Image',
            'audio'    => '🎵 Audio',
            'video'    => '🎥 Video',
            'document' => '📄 Document',
            'sticker'  => '😊 Sticker',
            default    => '[Media]',
        };
    }
}
