-- Pro-Tenant-Einstellungen & Branding (TEN-03, siehe core-kanban/tickets/TEN-03.md).
-- Alle Spalten NULLABLE: ein fehlender Wert bedeutet "System-Default
-- verwenden" (Akzeptanzkriterium 2), niemals ein Fehler.
CREATE TABLE tenant_settings (
    tenant_id    UUID PRIMARY KEY REFERENCES tenants(id),
    display_name TEXT,
    logo_url     TEXT,
    color_scheme TEXT,
    timezone     TEXT,
    language     TEXT,
    version      INT NOT NULL DEFAULT 0,
    updated_at   TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE tenant_settings_history (
    id           UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    tenant_id    UUID NOT NULL,
    display_name TEXT,
    logo_url     TEXT,
    color_scheme TEXT,
    timezone     TEXT,
    language     TEXT,
    version      INT NOT NULL,
    changed_at   TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX tenant_settings_history_tenant_idx ON tenant_settings_history (tenant_id, version);
