<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Tenant-owned operational preferences — one row per tenant, edited by the
 * tenant's own admins from inside the app.
 *
 * Distinct from `tenant_settings`, which is landlord-controlled (branding,
 * business identity, theme, the POS master switches) and only reachable from
 * Master Control. Anything a shop owner should be able to change for
 * themselves, without asking the landlord, belongs here instead.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('app_settings', function (Blueprint $table) {
            $table->id();
            // No DB-level FK on tenant_id, matching every other owned table.
            $table->unsignedBigInteger('tenant_id')->nullable()->unique();

            // How many days out from a sales order's delivery deadline the date
            // starts showing as urgent (red) in the listing. 0 disables the
            // highlight entirely; overdue is always highlighted regardless.
            $table->unsignedSmallInteger('sales_order_deadline_warning_days')->default(3);

            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('app_settings');
    }
};
