<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ReminderNotificationLog extends Model
{
    protected $table = 'notification_logs';

    protected $fillable = [
        'business_id','branch_id','customer_id','loan_id','loan_installment_id','notification_template_id',
        'reminder_type','days_from_due','channel','recipient','subject','message','scheduled_for','status',
        'provider_response','error','attempts','last_attempt_at','delivered_at','idempotency_key',
    ];

    protected function casts(): array
    {
        return [
            'days_from_due'=>'integer','scheduled_for'=>'date','attempts'=>'integer',
            'last_attempt_at'=>'datetime','delivered_at'=>'datetime',
        ];
    }

    public function business(): BelongsTo { return $this->belongsTo(Business::class); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function customer(): BelongsTo { return $this->belongsTo(Customer::class); }
    public function loan(): BelongsTo { return $this->belongsTo(Loan::class); }
    public function installment(): BelongsTo { return $this->belongsTo(LoanInstallment::class, 'loan_installment_id'); }
    public function template(): BelongsTo { return $this->belongsTo(NotificationTemplate::class, 'notification_template_id'); }
}
