import GenesisEquivalenceGateResult from "./GenesisEquivalenceGateResult.js";
import GraphModelMigrationFinalizationConfirmation from "./GraphModelMigrationFinalizationConfirmation.js";
import GraphModelMigrationRuntimeConformanceResult from "./GraphModelMigrationRuntimeConformanceResult.js";
import GraphModelMigrationScratchRef from "./GraphModelMigrationScratchRef.js";
import WarpError from "../errors/WarpError.js";
/** Pure finalization request envelope; it does not move Git refs. */
export default class GraphModelMigrationFinalizationRequest {
    liveRefName;
    expectedLiveHead;
    observedLiveHead;
    scratchRef;
    scratchHead;
    archiveRefName;
    confirmation;
    gateResult;
    runtimeConformance;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.liveRefName = requireNonEmptyString(checkedFields.liveRefName, 'liveRefName');
        this.expectedLiveHead = requireOptionalString(checkedFields.expectedLiveHead, 'expectedLiveHead');
        this.observedLiveHead = requireOptionalString(checkedFields.observedLiveHead, 'observedLiveHead');
        this.scratchRef = requireOptionalScratchRef(checkedFields.scratchRef);
        this.scratchHead = requireOptionalString(checkedFields.scratchHead, 'scratchHead');
        this.archiveRefName = requireOptionalString(checkedFields.archiveRefName, 'archiveRefName');
        this.confirmation = requireOptionalConfirmation(checkedFields.confirmation);
        this.gateResult = requireOptionalGateResult(checkedFields.gateResult);
        this.runtimeConformance = requireOptionalRuntimeConformance(checkedFields.runtimeConformance);
        Object.freeze(this);
    }
}
function requireFields(fields) {
    if (fields === null || fields === undefined) {
        throw new WarpError('GraphModelMigrationFinalizationRequest fields must be provided', 'E_VALIDATION');
    }
    return fields;
}
function requireNonEmptyString(value, name) {
    if (typeof value !== 'string' || value.length === 0) {
        throw new WarpError(`${name} must be a non-empty string`, 'E_VALIDATION');
    }
    return value;
}
function requireOptionalString(value, name) {
    if (value !== null && (typeof value !== 'string' || value.length === 0)) {
        throw new WarpError(`${name} must be a non-empty string or null`, 'E_VALIDATION');
    }
    return value;
}
function requireOptionalScratchRef(scratchRef) {
    if (scratchRef !== null && !(scratchRef instanceof GraphModelMigrationScratchRef)) {
        throw new WarpError('scratchRef must be a GraphModelMigrationScratchRef or null', 'E_VALIDATION');
    }
    return scratchRef;
}
function requireOptionalConfirmation(confirmation) {
    if (confirmation !== null && !(confirmation instanceof GraphModelMigrationFinalizationConfirmation)) {
        throw new WarpError('confirmation must be a GraphModelMigrationFinalizationConfirmation or null', 'E_VALIDATION');
    }
    return confirmation;
}
function requireOptionalGateResult(gateResult) {
    if (gateResult !== null && !(gateResult instanceof GenesisEquivalenceGateResult)) {
        throw new WarpError('gateResult must be a GenesisEquivalenceGateResult or null', 'E_VALIDATION');
    }
    return gateResult;
}
function requireOptionalRuntimeConformance(runtimeConformance) {
    if (runtimeConformance !== null
        && !(runtimeConformance instanceof GraphModelMigrationRuntimeConformanceResult)) {
        throw new WarpError('runtimeConformance must be a GraphModelMigrationRuntimeConformanceResult or null', 'E_VALIDATION');
    }
    return runtimeConformance;
}
