<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class DocumentSetting extends Model
{
    protected $fillable = [
        'file_name_pattern',
        'date_format',
        'unresolved_policy',
        'preview_enabled',
        'whitelist',
        'date_formats',
        'custom_defaults',
    ];

    protected $casts = [
        'preview_enabled' => 'boolean',
        'whitelist' => 'array',
        'date_formats' => 'array',
        'custom_defaults' => 'array',
    ];

    public static function instance(): self
    {
        return static::query()->first() ?? static::create([
            'file_name_pattern' => config('documents.file_name_pattern'),
            'date_format' => config('documents.date_format'),
            'unresolved_policy' => config('documents.unresolved_policy'),
            'preview_enabled' => config('documents.preview.enabled', true),
            'whitelist' => config('documents.whitelist'),
            'date_formats' => [],
            'custom_defaults' => [],
        ]);
    }
}
