<?php

namespace App\Models;

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

class SmsLog extends Model
{
    use HasFactory;

    protected $table = 'sms_logs';

    protected $fillable = [
        'uuid',
        'profile_id',
        'template_id',
        'to_number',
        'sender',
        'message',
        'status',
        'provider_message_id',
        'error_code',
        'error_message',
        'cost',
        'currency',
        'meta',
        'queued_at',
        'sent_at',
        'delivered_at',
        'failed_at',
    ];

    protected $casts = [
        'meta' => 'array',
        'queued_at' => 'datetime',
        'sent_at' => 'datetime',
        'delivered_at' => 'datetime',
        'failed_at' => 'datetime',
        'cost' => 'decimal:2',
    ];

    public function profile()
    {
        return $this->belongsTo(SmsProfile::class, 'profile_id');
    }

    public function template()
    {
        return $this->belongsTo(SmsTemplate::class, 'template_id');
    }
}
