<?php

namespace App\Models;

use App\Enums\TenantAnnouncementDeliveryStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class TenantAnnouncementDelivery extends Model
{
    protected $fillable = [
        'tenant_announcement_id',
        'tenant_id',
        'channel',
        'status',
        'sent_at',
        'failed_at',
        'failure_reason',
    ];

    protected function casts(): array
    {
        return [
            'status' => TenantAnnouncementDeliveryStatus::class,
            'sent_at' => 'datetime',
            'failed_at' => 'datetime',
        ];
    }

    public function announcement(): BelongsTo
    {
        return $this->belongsTo(TenantAnnouncement::class, 'tenant_announcement_id');
    }

    public function tenant(): BelongsTo
    {
        return $this->belongsTo(Tenant::class);
    }
}
