<?php

namespace App\Models\Settings;

use App\Models\Concerns\BelongsToTenant;
use App\Services\AppSettings;
use Illuminate\Database\Eloquent\Model;

/**
 * The tenant's own operational preferences — one row per tenant, editable by
 * the tenant's admins from inside the app.
 *
 * Read through {@see AppSettings} rather than directly, so a tenant with no row
 * yet still gets the documented defaults instead of nulls.
 */
class AppSetting extends Model
{
    use BelongsToTenant;

    /**
     * Applied when a tenant has no settings row yet.
     */
    public const DEFAULTS = [
        'sales_order_deadline_warning_days' => 3,
        'sales_order_auto_invoice' => false,
    ];

    protected $fillable = [
        'tenant_id',
        'sales_order_deadline_warning_days',
        'sales_order_auto_invoice',
    ];

    protected function casts(): array
    {
        return [
            'sales_order_deadline_warning_days' => 'integer',
            'sales_order_auto_invoice' => 'boolean',
        ];
    }
}
