import { createBaseState, defaultBaseState } from "document-model";
import { utils } from "./utils.js";
export function defaultGlobalState() {
    return {
        owner: null,
        label: null,
        genericSubdomain: null,
        genericBaseDomain: null,
        customDomain: {
            enabled: false,
            domain: null,
            dnsRecords: [],
        },
        defaultPackageRegistry: null,
        services: [],
        packages: [],
        status: "DRAFT",
        apexService: null,
        autoUpdateChannel: null,
        runtimeConfig: null,
    };
}
export function defaultLocalState() {
    return {};
}
export function defaultPHState() {
    return {
        ...defaultBaseState(),
        global: defaultGlobalState(),
        local: defaultLocalState(),
    };
}
export function createGlobalState(state) {
    return {
        ...defaultGlobalState(),
        ...(state || {}),
    };
}
export function createLocalState(state) {
    return {
        ...defaultLocalState(),
        ...(state || {}),
    };
}
export function createState(baseState, globalState, localState) {
    return {
        ...createBaseState(baseState?.auth, baseState?.document),
        global: createGlobalState(globalState),
        local: createLocalState(localState),
    };
}
/**
 * Creates a VetraCloudEnvironmentDocument with custom global and local state
 * This properly handles the PHBaseState requirements while allowing
 * document-specific state to be set.
 */
export function createVetraCloudEnvironmentDocument(state) {
    const document = utils.createDocument(createState(createBaseState(state?.auth, { version: 1, ...state?.document }), state?.global, state?.local));
    return document;
}
