<?php

namespace App\Models;

use App\Traits\Owned;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

enum WebhookMessageStatus: string {
    case Pending  = 'pending';
    case Sent     = 'sent';
    case Error    = 'error';
    case NoHook   = 'no-hook';
};


class WebhookMessage extends Model
{
    use SoftDeletes;
    use Owned;

    protected $table = 'webhook_messages';

    protected $fillable = [
        'key',
        'message_type',
        'status',
        'payload',
        'organisation_id',
        'webhook_id',
        'sent_at'
    ];

    protected $casts = [
        'key'               => 'string',
        'message_type'      => WebhookUsageType::class,
        'status'            => WebhookMessageStatus::class,
        'payload'           => 'array',
        'organisation_id'   => 'integer',
        'webhook_id'        => 'integer',
        'sent_at'           => 'datetime'
    ];

    public function scopeOrganisation($query, $organisation_id)
    {
        return $query->where('organisation_id', $organisation_id);
    }

}