import GraphModelMigrationFinalizationRequest from "./GraphModelMigrationFinalizationRequest.js";
import GraphModelMigrationNotice from "./GraphModelMigrationNotice.js";
import WarpError from "../errors/WarpError.js";
/** Pure safety decision for graph-model migration finalization. */
export default class GraphModelMigrationFinalizationSafetyResult {
    request;
    fatalErrors;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.request = requireRequest(checkedFields.request);
        this.fatalErrors = freezeFatalNotices(checkedFields.fatalErrors);
        Object.freeze(this);
    }
    /** Returns true when finalization may move to the Git ref update step. */
    allowsFinalization() {
        return this.fatalErrors.length === 0;
    }
}
function requireFields(fields) {
    if (fields === null || fields === undefined) {
        throw new WarpError('GraphModelMigrationFinalizationSafetyResult fields must be provided', 'E_VALIDATION');
    }
    return fields;
}
function requireRequest(request) {
    if (!(request instanceof GraphModelMigrationFinalizationRequest)) {
        throw new WarpError('request must be a GraphModelMigrationFinalizationRequest', 'E_VALIDATION');
    }
    return request;
}
function freezeFatalNotices(fatalErrors) {
    if (!Array.isArray(fatalErrors)) {
        throw new WarpError('fatalErrors must be an array', 'E_VALIDATION');
    }
    return Object.freeze(fatalErrors.map(requireFatalNotice));
}
function requireFatalNotice(notice) {
    if (!(notice instanceof GraphModelMigrationNotice) || !notice.isFatal()) {
        throw new WarpError('fatalErrors must contain fatal migration notices', 'E_VALIDATION');
    }
    return notice;
}
