<?php

namespace App\Models\Contact;

use App\Enum\Contact\MessageChannel;
use App\Trait\BelongsToSolicitor;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class ContactSuppression extends Model
{
    use BelongsToSolicitor;

    protected $table = 'contact_suppressions';

    protected $fillable = [
        'solicitor_id',
        'channel',
        'value',
        'reason',
        'source_type',
        'source_id',
        'suppressed_at',
    ];

    protected $casts = [
        'channel' => MessageChannel::class,
        'suppressed_at' => 'datetime',
    ];

    public function source(): MorphTo
    {
        return $this->morphTo();
    }

    public function scopeForChannel(Builder $q, MessageChannel $channel): Builder
    {
        return $q->where('channel', $channel->value);
    }

    public function scopeForValue(Builder $q, string $value): Builder
    {
        return $q->where('value', $value);
    }
}
