<?php

namespace App\Models\Contact\Hub;

use App\Enum\Contact\MessageEventType;
use App\Enum\Contact\MessageStatus;
use App\Trait\BelongsToSolicitor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ContactMessageEvent extends Model
{
    use BelongsToSolicitor;

    protected $table = 'contact_message_events';

    protected $fillable = [
        'contact_message_id',
        'solicitor_id',
        'event_type',
        'provider_event_id',
        'mapped_status',
        'payload',
        'occurred_at',
    ];

    protected $casts = [
        'event_type' => MessageEventType::class,
        'mapped_status' => MessageStatus::class,
        'payload' => 'array',
        'occurred_at' => 'datetime',
    ];

    public function message(): BelongsTo
    {
        return $this->belongsTo(ContactMessage::class, 'contact_message_id');
    }
}
