<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class NotificationMessage extends Model
{
    protected $guarded = ['id'];

    protected function casts(): array
    {
        return ['payload' => 'array', 'context' => 'array', 'scheduled_at' => 'datetime'];
    }

    public function event()
    {
        return $this->belongsTo(NotificationEvent::class, 'notification_event_id');
    }

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

    public function deliveries()
    {
        return $this->hasMany(NotificationDelivery::class);
    }

    public function broadcast()
    {
        return $this->belongsTo(NotificationBroadcast::class, 'notification_broadcast_id');
    }

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

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