<?php

namespace App\Models;

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

class WhatsAppMessage extends Model
{
    /** Laravel pluraliza mal: WhatsAppMessage → whats_app_messages; la migración crea whatsapp_messages. */
    protected $table = 'whatsapp_messages';

    protected $fillable = [
        'phone',
        'sender_type',
        'message_type',
        'body',
        'meta',
        'user_id',
    ];

    protected $casts = [
        'meta' => \App\Casts\SafeJsonArray::class,
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

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