<?php

namespace App\Models;

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

class NotificationCampaign extends Model
{
    protected $fillable = [
        'tenant_id',
        'created_by',
        'recipient_type',
        'subject',
        'message',
        'channels',
        'audience_type',
        'audience_filters',
        'status',
        'total_recipients',
        'email_sent_count',
        'sms_sent_count',
        'portal_alert_count',
        'whatsapp_sent_count',
        'failed_count',
        'sent_at',
    ];

    protected function casts(): array
    {
        return [
            'channels' => 'array',
            'audience_filters' => 'array',
            'sent_at' => 'datetime',
        ];
    }

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

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

    public function recipients(): HasMany
    {
        return $this->hasMany(NotificationCampaignRecipient::class);
    }
}
