<?php

namespace App\Models;

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

enum WebhookHookType: string {
    case Slack      = 'slack';
    case Google     = 'google';
    case Discord    = 'discord';
    case Raw        = 'raw';
    case Other1     = 'other_1';
    case Other2     = 'other_2';
    case Other3     = 'other_3';
    case Other4     = 'other_4';
    case Other5     = 'other_5';
    case Other6     = 'other_6';
    case Other7     = 'other_7';
    case Other8     = 'other_8';
    case Other9     = 'other_9';
};

enum WebhookUsageType: string {
    case Reporting  = 'reporting';
    // The Oculi backed Mitigation - Attacks pipeline. Deliberately its own type: hooks must opt in to
    // receive the new notifications, so nothing reaches a customer until they (or we) flip a hook over.
    case Mitigation = 'mitigation';
    case Other1     = 'other_1';
    case Other2     = 'other_2';
    case Other3     = 'other_3';
    case Other4     = 'other_4';
    case Other5     = 'other_5';
    case Other6     = 'other_6';
    case Other7     = 'other_7';
    case Other8     = 'other_8';
    case Other9     = 'other_9';
};

class Webhook extends Model
{
    use SoftDeletes, Owned;

    protected $table = 'webhooks';

    protected $fillable = [
        'name',
        'hook',
        'hook_type',
        'usage_type',
        'organisation_id'
    ];

    protected $casts = [
        'hook' => 'string',
        'hook_type' => WebhookHookType::class,
        'usage_type' => WebhookUsageType::class,
        'organisation_id' => 'integer'
    ];

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

}