<?php

namespace App\Services;

use App\Models\Central\Tenant;

/**
 * Typed read access to the landlord-controlled VAT master switch (Master
 * Control → Invoice → "VAT registered"), off by default. This is the one
 * place every VAT-adjacent surface — ProductResource, InvoiceResource, the
 * POS terminal, SalesOrderResource, InvoiceService, SalesOrderService,
 * InvoiceDocument/print — reads the flag from, so a tenant that has not
 * turned VAT on can never see or be charged it, and a landlord flips one
 * switch to change that for the whole tenant.
 */
class VatSettings
{
    public function enabled(): bool
    {
        $tenant = app(CurrentContext::class)->tenant();

        if (! $tenant) {
            return false;
        }

        return $this->enabledForTenant($tenant);
    }

    public function enabledForTenant(Tenant $tenant): bool
    {
        return (bool) ($tenant->settingsRow?->invoice_vat_enabled ?? false);
    }
}
