<?php

namespace App\Models;

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

class DailyBranchReportDelivery extends Model
{
    public const STATUSES = ['pending', 'sent', 'failed'];

    protected $fillable = [
        'daily_branch_report_id', 'recipient_id', 'channel', 'recipient_name', 'recipient', 'status',
        'attempts', 'provider_message_id', 'provider_response', 'error_message', 'last_attempt_at', 'sent_at',
    ];

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

    public function report(): BelongsTo { return $this->belongsTo(DailyBranchReport::class, 'daily_branch_report_id'); }
    public function configuredRecipient(): BelongsTo { return $this->belongsTo(DailyBranchReportRecipient::class, 'recipient_id')->withTrashed(); }
}
