<?php

namespace App\Models;

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

class DocumentTemplate extends Model
{
    use HasFactory;

    protected $fillable = [
        'name', 'slug', 'custom_name', 'description', 'core_entity', 'entities', 'columns', 'tokens', 'version', 'engine', 'file_path', 'file_hash', 'file_size', 'mime_type', 'active', 'created_by', 'updated_by',
        'output_filename_pattern', 'date_format', 'fail_on_unresolved', 'formatting_options', 'meta', 'action_id', 'decision_id', 'activity_note_template',
    ];

    protected $casts = [
        'entities' => 'array',
        'columns' => 'array',
        'tokens' => 'array',
        'active' => 'boolean',
        'version' => 'integer',
        'fail_on_unresolved' => 'boolean',
        'formatting_options' => 'array',
        'meta' => 'array',
    ];

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

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

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updater(): BelongsTo
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
