<?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 = [
        'phone_number',
        'message',
        'template_id',
        'gateway',
        'status',
        'response',
        'sms_count',
        'cost',
        'purpose',
        'reference_id',
        'reference_type',
        'sent_by',
        'sent_at'
    ];

    protected $casts = [
        'sent_at' => 'datetime',
        'cost' => 'decimal:2',
        'sms_count' => 'integer'
    ];

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

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

    public function reference()
    {
        return $this->morphTo();
    }

    // Status types
    public static function getStatusTypes()
    {
        return [
            'pending' => 'অপেক্ষমাণ',
            'sent' => 'পাঠানো হয়েছে',
            'delivered' => 'পৌঁছেছে',
            'failed' => 'ব্যর্থ',
            'cancelled' => 'বাতিল'
        ];
    }

    // Purpose types
    public static function getPurposeTypes()
    {
        return [
            'admission' => 'ভর্তি',
            'fee_payment' => 'ফি পরিশোধ',
            'exam_result' => 'পরীক্ষার ফলাফল',
            'attendance' => 'উপস্থিতি',
            'holiday' => 'ছুটির তথ্য',
            'notice' => 'নোটিশ',
            'emergency' => 'জরুরি বার্তা',
            'reminder' => 'রিমাইন্ডার',
            'birthday' => 'জন্মদিন',
            'custom' => 'কাস্টম'
        ];
    }
}