<?php

namespace App\Models;

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

class WhatsappMessageTranslation extends Model
{
    use HasFactory;

    protected $table = 'whatsapp_message_translations';
    public $incrementing = false;
    protected $keyType = 'string';

    protected $fillable = [
        'whatsapp_message_id',
        'franchisee_id',
        'language_code',
        'header_text',
        'body_text',
        'footer_text',
        'options',
    ];

    protected $casts = [
        'options' => 'array',
    ];

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            if (empty($model->id)) {
                $model->id = (string) Str::uuid();
            }
        });
    }

    public function message()
    {
        return $this->belongsTo(WhatsappMessage::class, 'whatsapp_message_id');
    }

    public function franchisee()
    {
        return $this->belongsTo(Franchisee::class, 'franchisee_id');
    }
}
