<?php

namespace App\Models;

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

class SmsSchedule extends Model
{
    use HasFactory;

    protected $table = 'sms_schedules';
    
    protected $fillable = [
        'name',
        'recipient_type', // all_students, class, individual, custom
        'recipients', // JSON array or query
        'template_id',
        'custom_message',
        'scheduled_at',
        'status', // pending, processing, completed, cancelled
        'sent_count',
        'failed_count',
        'created_by',
        'completed_at'
    ];

    protected $casts = [
        'recipients' => 'array',
        'scheduled_at' => 'datetime',
        'completed_at' => 'datetime',
        'sent_count' => 'integer',
        'failed_count' => 'integer'
    ];

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

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

    // Status types
    public static function getStatusTypes()
    {
        return [
            'pending' => 'অপেক্ষমাণ',
            'processing' => 'প্রক্রিয়াধীন',
            'completed' => 'সম্পন্ন',
            'cancelled' => 'বাতিল'
        ];
    }

    // Recipient types
    public static function getRecipientTypes()
    {
        return [
            'all_students' => 'সকল ছাত্র',
            'all_teachers' => 'সকল শিক্ষক',
            'all_guardians' => 'সকল অভিভাবক',
            'class' => 'শ্রেণি ভিত্তিক',
            'individual' => 'ব্যক্তিগত',
            'custom' => 'কাস্টম'
        ];
    }
}