import QueryError from "../../errors/QueryError.js";
const CHECKPOINT_TAIL_BASIS_VERIFIED_POSTURE = 'checkpoint-tail-basis-verified';
const ABSENT_BASIS_POSTURE = 'absent';
const UNSUPPORTED_BASIS_POSTURE = 'unsupported';
const RESIDUAL_BASIS_POSTURE = 'residual';
export const OPTIC_BASIS_POSTURES = Object.freeze([
    CHECKPOINT_TAIL_BASIS_VERIFIED_POSTURE,
    ABSENT_BASIS_POSTURE,
    UNSUPPORTED_BASIS_POSTURE,
    RESIDUAL_BASIS_POSTURE,
]);
export default class OpticBasisPosture {
    value;
    constructor(value) {
        this.value = requireOpticBasisPostureValue(value);
        Object.freeze(this);
    }
    static checkpointTailBasisVerified() {
        return new OpticBasisPosture(CHECKPOINT_TAIL_BASIS_VERIFIED_POSTURE);
    }
    static absent() {
        return new OpticBasisPosture(ABSENT_BASIS_POSTURE);
    }
    static unsupported() {
        return new OpticBasisPosture(UNSUPPORTED_BASIS_POSTURE);
    }
    static residual() {
        return new OpticBasisPosture(RESIDUAL_BASIS_POSTURE);
    }
    isCheckpointTailBasisVerified() {
        return this.value === CHECKPOINT_TAIL_BASIS_VERIFIED_POSTURE;
    }
    equals(other) {
        return this.value === other.value;
    }
    toString() {
        return this.value;
    }
}
export function requireOpticBasisPostureValue(value) {
    if (typeof value !== 'string') {
        throwOpticBasisPostureError();
    }
    const valid = OPTIC_BASIS_POSTURES.find((candidate) => candidate === value);
    if (valid === undefined) {
        throwOpticBasisPostureError();
    }
    return valid;
}
function throwOpticBasisPostureError() {
    throw new QueryError('Optic basis posture is invalid.', {
        code: 'E_OPTIC_SCHEMA',
        context: { field: 'basisPosture' },
    });
}
