"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateArchiveSourceEntry = validateArchiveSourceEntry;
const ACTIVE_SPEC_REGISTRY_STATUS = "active";
const ARCHIVED_SPEC_REGISTRY_STATUS = "archived";
const SPEC_REGISTRY_INDEX_PATH = ".day-shift/specs/index.json";
function validateArchiveSourceEntry(entryId, currentDocument) {
    const targetIndex = currentDocument.entries.findIndex((entry) => entry.id === entryId);
    if (targetIndex === -1) {
        return {
            ok: false,
            findings: [
                createFinding("SPEC_ARCHIVE_ENTRY_NOT_FOUND", `Spec id '${entryId}' does not exist in the registry index.`, "error", SPEC_REGISTRY_INDEX_PATH)
            ]
        };
    }
    const targetEntry = currentDocument.entries[targetIndex];
    if (targetEntry.status === ARCHIVED_SPEC_REGISTRY_STATUS) {
        return {
            ok: false,
            findings: [
                createFinding("SPEC_ARCHIVE_ALREADY_ARCHIVED", `Spec id '${entryId}' is already archived.`, "error", SPEC_REGISTRY_INDEX_PATH)
            ]
        };
    }
    if (targetEntry.status !== ACTIVE_SPEC_REGISTRY_STATUS) {
        return {
            ok: false,
            findings: [
                createFinding("SPEC_ARCHIVE_INVALID_SOURCE_STATUS", `Spec id '${entryId}' must be in status '${ACTIVE_SPEC_REGISTRY_STATUS}' before it can be archived; received '${targetEntry.status}'.`, "error", SPEC_REGISTRY_INDEX_PATH)
            ]
        };
    }
    return {
        ok: true,
        targetIndex,
        targetEntry
    };
}
function createFinding(code, message, severity, path) {
    const finding = {
        code,
        message,
        severity
    };
    if (path !== undefined) {
        finding.path = path;
    }
    return finding;
}
