import ContinuumEvidenceAccess from "./ContinuumEvidenceAccess.js";
import ContinuumEvidenceCompleteness from "./ContinuumEvidenceCompleteness.js";
import ContinuumEvidenceOrigin from "./ContinuumEvidenceOrigin.js";
import ContinuumEvidenceProofStrength from "./ContinuumEvidenceProofStrength.js";
import WarpError from "../errors/WarpError.js";
const LATTICE_SEPARATOR = ':';
/** Runtime-backed four-coordinate evidence posture for Continuum-family values. */
export default class ContinuumEvidencePosture {
    origin;
    proofStrength;
    access;
    completeness;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.origin = normalizeOrigin(checkedFields.origin);
        this.proofStrength = normalizeProofStrength(checkedFields.proofStrength);
        this.access = normalizeAccess(checkedFields.access);
        this.completeness = normalizeCompleteness(checkedFields.completeness);
        Object.freeze(this);
    }
    static translatedGitWarpEvidence() {
        return new ContinuumEvidencePosture({
            origin: ContinuumEvidenceOrigin.translated(),
            proofStrength: ContinuumEvidenceProofStrength.witnessed(),
            access: ContinuumEvidenceAccess.available(),
            completeness: ContinuumEvidenceCompleteness.complete(),
        });
    }
    static nativeContinuumEvidence() {
        return new ContinuumEvidencePosture({
            origin: ContinuumEvidenceOrigin.native(),
            proofStrength: ContinuumEvidenceProofStrength.witnessed(),
            access: ContinuumEvidenceAccess.available(),
            completeness: ContinuumEvidenceCompleteness.complete(),
        });
    }
    static unsupportedDescriptor() {
        return new ContinuumEvidencePosture({
            origin: ContinuumEvidenceOrigin.descriptor(),
            proofStrength: ContinuumEvidenceProofStrength.none(),
            access: ContinuumEvidenceAccess.available(),
            completeness: ContinuumEvidenceCompleteness.unsupported(),
        });
    }
    /** Returns true for git-warp-local facts translated into Continuum shape. */
    isTranslatedGitWarpEvidence() {
        return this.origin.isTranslated()
            && this.proofStrength.isWitnessed()
            && this.access.isAvailable()
            && this.completeness.isComplete();
    }
    /** Returns true only for values with native Continuum witnesshood proof. */
    isNativeContinuumEvidence() {
        return this.origin.isNative() && this.proofStrength.isWitnessed();
    }
    /** Returns true when a native proof string must accompany this posture. */
    requiresNativeWitnessProof() {
        return this.origin.isNative() && this.proofStrength.isWitnessed() && this.access.isAvailable();
    }
    /** Returns true when direct replay can trust this posture without expansion. */
    canAuthorizeReplayShortcut() {
        return this.origin.isReplayOrigin()
            && this.proofStrength.isWitnessed()
            && this.access.isAvailable()
            && this.completeness.isComplete();
    }
    /** Returns true when the posture is shape-only descriptor evidence. */
    isUnsupportedDescriptor() {
        return this.origin.equals(ContinuumEvidenceOrigin.descriptor())
            && this.proofStrength.hasNoProof()
            && this.completeness.isUnsupported();
    }
    /** Returns the stable four-coordinate lattice key. */
    toString() {
        return [
            this.origin.toString(),
            this.proofStrength.toString(),
            this.access.toString(),
            this.completeness.toString(),
        ].join(LATTICE_SEPARATOR);
    }
}
function requireFields(value) {
    if (value === null || value === undefined) {
        throw new WarpError('ContinuumEvidencePosture fields must be provided', 'E_VALIDATION');
    }
    return value;
}
function normalizeOrigin(value) {
    if (value instanceof ContinuumEvidenceOrigin) {
        return value;
    }
    return new ContinuumEvidenceOrigin(value);
}
function normalizeProofStrength(value) {
    if (value instanceof ContinuumEvidenceProofStrength) {
        return value;
    }
    return new ContinuumEvidenceProofStrength(value);
}
function normalizeAccess(value) {
    if (value instanceof ContinuumEvidenceAccess) {
        return value;
    }
    return new ContinuumEvidenceAccess(value);
}
function normalizeCompleteness(value) {
    if (value instanceof ContinuumEvidenceCompleteness) {
        return value;
    }
    return new ContinuumEvidenceCompleteness(value);
}
