<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;

class EmailTemplate extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'key',
        'subject_template',
        'html_template',
        'text_template',
        'entity_types',
        'allow_attachments',
        'active',
        'action_id',
        'decision_id',
        'client',
    ];

    protected $casts = [
        'active' => 'boolean',
        'client' => 'boolean',
        'entity_types' => 'array',
        'allow_attachments' => 'boolean',
    ];

    public function documents(): MorphMany
    {
        return $this->morphMany(Document::class, 'documentable');
    }

    public function action(): BelongsTo
    {
        return $this->belongsTo(Action::class);
    }

    public function decision(): BelongsTo
    {
        return $this->belongsTo(Decision::class);
    }
}
