<?php

namespace App\Models\Setting;

use Illuminate\Database\Eloquent\Model;

class EmailSender extends Model {
    protected $table = 'email_senders';

    protected $fillable = [
        'display_name',
        'email_address',
        'purpose',
        'is_default',
        'signature',
    ];

    protected $casts = [
        'is_default' => 'boolean',
    ];

    public static array $purposes = [
        'dsar'    => 'DSAR',
        'client'  => 'Client',
        'general' => 'General',
    ];

    public static function forPurpose(string $purpose): ?self {
        return static::where('purpose', $purpose)->orderByDesc('is_default')->first()
            ?? static::where('purpose', 'general')->orderByDesc('is_default')->first()
            ?? static::orderByDesc('is_default')->first();
    }
}
