-- lib/DcpRuntimePersistenceGate.lua
-- Phase 3F-BLOCKER-C6H: Freeze runtime DCP persistence while LR shows Profile missing.
-- Serwisowe only. DCP assets remain installed; XMP/foundation/LAB pipeline stays active.

local M = {}

-- Hard gate: set false only after C6H repair clears Profile missing + digest capture (G1–G5).
M.RUNTIME_DCP_DISABLED = true

-- Phase 3T-LR4: per-emulsion override — disabled by Phase 3T-LR8 CineStill behavioral rollback.
M.RUNTIME_DCP_EMULSION_ALLOW = {
}

local function trimEmulsionId(value)
    return (tostring(value or ""):gsub("^%s+", ""):gsub("%s+$", ""))
end

function M.isRuntimeDcpEmulsionOverrideEnabled(emulsionId)
    return M.RUNTIME_DCP_EMULSION_ALLOW[trimEmulsionId(emulsionId)] == true
end

function M.isRuntimeDcpDisabledForEmulsion(emulsionId)
    if M.isRuntimeDcpEmulsionOverrideEnabled(emulsionId) then
        return false
    end
    return M.RUNTIME_DCP_DISABLED == true
end

function M.isRuntimeDcpPersistenceDisabled()
    return M.RUNTIME_DCP_DISABLED == true
end

function M.isRuntimeDcpDisabled()
    return M.isRuntimeDcpPersistenceDisabled()
end

function M.gateReasonCode()
    return "runtime_dcp_disabled_c6h"
end

function M.gateStatus()
    return "profile_runtime_dcp_disabled"
end

function M.blockReason()
    return "profile_runtime_dcp_disabled"
end

function M.gateApplyCameraProfile(requested, emulsionId)
    if M.isRuntimeDcpDisabledForEmulsion(emulsionId) then
        return false, M.blockReason()
    end
    if requested == true then
        return true, "allowed"
    end
    return false, "not_requested"
end

function M.summaryLine()
    return "Runtime DCP persistence disabled (C6H). Film look via XMP/foundation/LAB/LUT only."
end

return M
