<?php
namespace App\Models;

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

class SmsScheduled extends Model
{
    use HasFactory;

    protected $table = 'sms_scheduled';

    protected $fillable = [
        'template_id',
        'content',
        'scheduled_at',
        'status',
        'created_by'
    ];

    protected $casts = [
        'scheduled_at' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

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

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function recipients()
    {
        return $this->belongsToMany(User::class, 'sms_scheduled_recipients', 'sms_scheduled_id', 'user_id');
    }
}
