import { n as __exportAll } from "./chunk-YKewjYmz.js";
import { A as array, F as object, I as string, N as literal, O as _enum, R as datetime, _ as defaultBaseState, a as BaseDocumentStateSchema, c as baseLoadFromInput, d as createAction, h as createState, i as BaseDocumentHeaderSchema, k as any, l as baseSaveToFileHandle, m as createReducer, o as baseActions, s as baseCreateDocument, y as isDocumentAction, z as generateId } from "./dist-DZj99xX4.js";
//#region document-models/tension/v1/gen/schema/zod.ts
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
const definedNonNullAnySchema = any().refine((v) => isDefinedNonNullAny(v));
const TensionStatusSchema = _enum([
	"DISSOLVED",
	"OPEN",
	"RESOLVED"
]);
function AddInvolvedRefInputSchema() {
	return object({ ref: string() });
}
function CreateTensionInputSchema() {
	return object({
		content: string().nullish(),
		description: string(),
		involvedRefs: array(string()),
		observedAt: datetime(),
		observedBy: string().nullish(),
		title: string()
	});
}
function DissolveTensionInputSchema() {
	return object({
		resolution: string(),
		resolvedAt: datetime()
	});
}
function ResolveTensionInputSchema() {
	return object({
		resolution: string(),
		resolvedAt: datetime()
	});
}
function TensionStateSchema() {
	return object({
		__typename: literal("TensionState").optional(),
		content: string().nullish(),
		description: string().nullish(),
		involvedRefs: array(string()),
		observedAt: datetime().nullish(),
		observedBy: string().nullish(),
		resolution: string().nullish(),
		resolvedAt: datetime().nullish(),
		status: TensionStatusSchema.nullish(),
		title: string().nullish()
	});
}
//#endregion
//#region document-models/tension/v1/gen/tension-management/creators.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
var creators_exports = /* @__PURE__ */ __exportAll({
	addInvolvedRef: () => addInvolvedRef,
	createTension: () => createTension,
	dissolveTension: () => dissolveTension,
	resolveTension: () => resolveTension
});
const createTension = (input) => createAction("CREATE_TENSION", { ...input }, void 0, CreateTensionInputSchema, "global");
const resolveTension = (input) => createAction("RESOLVE_TENSION", { ...input }, void 0, ResolveTensionInputSchema, "global");
const dissolveTension = (input) => createAction("DISSOLVE_TENSION", { ...input }, void 0, DissolveTensionInputSchema, "global");
const addInvolvedRef = (input) => createAction("ADD_INVOLVED_REF", { ...input }, void 0, AddInvolvedRefInputSchema, "global");
//#endregion
//#region document-models/tension/v1/actions.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
/** Actions for the Tension document model */
const actions = {
	...baseActions,
	...creators_exports
};
//#endregion
//#region document-models/tension/v1/gen/document-model.ts
const documentModel = {
	author: {
		name: "BAI",
		website: "https://bai.powerhouse.io/"
	},
	description: "Unresolved contradiction — tracks conflicts between knowledge claims with involved references and resolution status",
	extension: "",
	id: "bai/tension",
	name: "Tension",
	specifications: [{
		changeLog: [],
		modules: [{
			description: "Tension lifecycle",
			id: "tension-management",
			name: "tension-management",
			operations: [
				{
					description: "Identify a new contradiction",
					errors: [],
					examples: [],
					id: "create-tension",
					name: "CREATE_TENSION",
					reducer: "state.title = action.input.title;\nstate.description = action.input.description;\nstate.content = action.input.content || null;\nstate.involvedRefs = action.input.involvedRefs;\nstate.status = \"OPEN\";\nstate.observedAt = action.input.observedAt;\nstate.observedBy = action.input.observedBy || null;",
					schema: "input CreateTensionInput {\n    title: String!\n    description: String!\n    content: String\n    involvedRefs: [String!]!\n    observedAt: DateTime!\n    observedBy: String\n}",
					template: "Identify a new contradiction",
					scope: "global"
				},
				{
					description: "Mark as resolved with explanation",
					errors: [{
						code: "TENSION_ALREADY_RESOLVED",
						description: "Tension is not in OPEN status",
						id: "err-tension-already-resolved",
						name: "TensionAlreadyResolvedError",
						template: ""
					}],
					examples: [],
					id: "resolve-tension",
					name: "RESOLVE_TENSION",
					reducer: "if (state.status !== \"OPEN\") throw new TensionAlreadyResolvedError(\"Tension is not open\");\nstate.status = \"RESOLVED\";\nstate.resolution = action.input.resolution;\nstate.resolvedAt = action.input.resolvedAt;",
					schema: "input ResolveTensionInput {\n    resolution: String!\n    resolvedAt: DateTime!\n}",
					template: "Mark as resolved with explanation",
					scope: "global"
				},
				{
					description: "Mark as dissolved (apparent, not real)",
					errors: [{
						code: "TENSION_ALREADY_RESOLVED",
						description: "Tension is not in OPEN status",
						id: "err-tension-already-dissolved",
						name: "TensionAlreadyResolvedError",
						template: ""
					}],
					examples: [],
					id: "dissolve-tension",
					name: "DISSOLVE_TENSION",
					reducer: "if (state.status !== \"OPEN\") throw new TensionAlreadyResolvedError(\"Tension is not open\");\nstate.status = \"DISSOLVED\";\nstate.resolution = action.input.resolution;\nstate.resolvedAt = action.input.resolvedAt;",
					schema: "input DissolveTensionInput {\n    resolution: String!\n    resolvedAt: DateTime!\n}",
					template: "Mark as dissolved (apparent, not real)",
					scope: "global"
				},
				{
					description: "Add a note to the tension",
					errors: [],
					examples: [],
					id: "add-involved-ref",
					name: "ADD_INVOLVED_REF",
					reducer: "if (!state.involvedRefs.includes(action.input.ref)) {\n    state.involvedRefs.push(action.input.ref);\n}",
					schema: "input AddInvolvedRefInput {\n    ref: String!\n}",
					template: "Add a note to the tension",
					scope: "global"
				}
			]
		}],
		state: {
			global: {
				examples: [],
				initialValue: "{\n    \"title\": null,\n    \"description\": null,\n    \"content\": null,\n    \"involvedRefs\": [],\n    \"status\": \"OPEN\",\n    \"observedAt\": null,\n    \"observedBy\": null,\n    \"resolution\": null,\n    \"resolvedAt\": null\n}",
				schema: "enum TensionStatus {\n    OPEN\n    RESOLVED\n    DISSOLVED\n}\n\ntype TensionState {\n    title: String\n    description: String\n    content: String\n    involvedRefs: [String!]!\n    status: TensionStatus\n    observedAt: DateTime\n    observedBy: String\n    resolution: String\n    resolvedAt: DateTime\n}"
			},
			local: {
				examples: [],
				initialValue: "",
				schema: ""
			}
		},
		version: 1
	}]
};
//#endregion
//#region document-models/tension/v1/gen/tension-management/error.ts
var TensionAlreadyResolvedError = class extends Error {
	errorCode = "TensionAlreadyResolvedError";
	constructor(message = "TensionAlreadyResolvedError") {
		super(message);
	}
};
//#endregion
//#region document-models/tension/v1/src/reducers/tension-management.ts
const tensionTensionManagementOperations = {
	createTensionOperation(state, action) {
		state.title = action.input.title;
		state.description = action.input.description;
		state.content = action.input.content || null;
		state.involvedRefs = action.input.involvedRefs;
		state.status = "OPEN";
		state.observedAt = action.input.observedAt;
		state.observedBy = action.input.observedBy || null;
	},
	resolveTensionOperation(state, action) {
		if (state.status !== "OPEN") throw new TensionAlreadyResolvedError("Tension is not open");
		state.status = "RESOLVED";
		state.resolution = action.input.resolution;
		state.resolvedAt = action.input.resolvedAt;
	},
	dissolveTensionOperation(state, action) {
		if (state.status !== "OPEN") throw new TensionAlreadyResolvedError("Tension is not open");
		state.status = "DISSOLVED";
		state.resolution = action.input.resolution;
		state.resolvedAt = action.input.resolvedAt;
	},
	addInvolvedRefOperation(state, action) {
		if (!state.involvedRefs.includes(action.input.ref)) state.involvedRefs.push(action.input.ref);
	}
};
//#endregion
//#region document-models/tension/v1/gen/reducer.ts
const stateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	switch (action.type) {
		case "CREATE_TENSION":
			CreateTensionInputSchema().parse(action.input);
			tensionTensionManagementOperations.createTensionOperation(state[action.scope], action, dispatch);
			break;
		case "RESOLVE_TENSION":
			ResolveTensionInputSchema().parse(action.input);
			tensionTensionManagementOperations.resolveTensionOperation(state[action.scope], action, dispatch);
			break;
		case "DISSOLVE_TENSION":
			DissolveTensionInputSchema().parse(action.input);
			tensionTensionManagementOperations.dissolveTensionOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_INVOLVED_REF":
			AddInvolvedRefInputSchema().parse(action.input);
			tensionTensionManagementOperations.addInvolvedRefOperation(state[action.scope], action, dispatch);
			break;
		default: return state;
	}
};
const reducer = createReducer(stateReducer);
//#endregion
//#region document-models/tension/v1/gen/document-type.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
const tensionDocumentType = "bai/tension";
//#endregion
//#region document-models/tension/v1/gen/document-schema.ts
/**
* WARNING: DO NOT EDIT
* This file is auto-generated and updated by codegen
*/
/** Schema for validating the header object of a Tension document */
const TensionDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal(tensionDocumentType) });
/** Schema for validating the state object of a Tension document */
const TensionPHStateSchema = BaseDocumentStateSchema.extend({ global: TensionStateSchema() });
const TensionDocumentSchema = object({
	header: TensionDocumentHeaderSchema,
	state: TensionPHStateSchema,
	initialState: TensionPHStateSchema
});
/** Simple helper function to check if a state object is a Tension document state object */
function isTensionState(state) {
	return TensionPHStateSchema.safeParse(state).success;
}
/** Simple helper function to assert that a document state object is a Tension document state object */
function assertIsTensionState(state) {
	TensionPHStateSchema.parse(state);
}
/** Simple helper function to check if a document is a Tension document */
function isTensionDocument(document) {
	return TensionDocumentSchema.safeParse(document).success;
}
/** Simple helper function to assert that a document is a Tension document */
function assertIsTensionDocument(document) {
	TensionDocumentSchema.parse(document);
}
//#endregion
//#region document-models/tension/v1/gen/utils.ts
const initialGlobalState = {
	title: null,
	description: null,
	content: null,
	involvedRefs: [],
	status: "OPEN",
	observedAt: null,
	observedBy: null,
	resolution: null,
	resolvedAt: null
};
const initialLocalState = {};
const utils$1 = {
	fileExtension: "",
	createState(state) {
		return {
			...defaultBaseState(),
			global: {
				...initialGlobalState,
				...state?.global
			},
			local: {
				...initialLocalState,
				...state?.local
			}
		};
	},
	createDocument(state) {
		const document = baseCreateDocument(utils$1.createState, state);
		document.header.documentType = tensionDocumentType;
		document.header.id = generateId();
		return document;
	},
	saveToFileHandle(document, input) {
		return baseSaveToFileHandle(document, input);
	},
	loadFromInput(input) {
		return baseLoadFromInput(input, reducer);
	},
	isStateOfType(state) {
		return isTensionState(state);
	},
	assertIsStateOfType(state) {
		return assertIsTensionState(state);
	},
	isDocumentOfType(document) {
		return isTensionDocument(document);
	},
	assertIsDocumentOfType(document) {
		return assertIsTensionDocument(document);
	}
};
//#endregion
//#region document-models/tension/v1/src/utils.ts
var utils_exports = /* @__PURE__ */ __exportAll({});
//#endregion
//#region document-models/tension/v1/utils.ts
/** Utils for the Tension document model */
const utils = {
	...utils$1,
	...utils_exports
};
//#endregion
//#region document-models/tension/v1/module.ts
/** Document model module for the Tension document type */
const Tension = {
	version: 1,
	reducer,
	actions,
	utils,
	documentModel: createState(defaultBaseState(), documentModel)
};
//#endregion
export { CreateTensionInputSchema as C, TensionStatusSchema as D, TensionStateSchema as E, definedNonNullAnySchema as O, AddInvolvedRefInputSchema as S, ResolveTensionInputSchema as T, addInvolvedRef as _, utils$1 as a, dissolveTension as b, TensionPHStateSchema as c, isTensionDocument as d, isTensionState as f, actions as g, documentModel as h, initialLocalState as i, isDefinedNonNullAny as k, assertIsTensionDocument as l, reducer as m, utils as n, TensionDocumentHeaderSchema as o, tensionDocumentType as p, initialGlobalState as r, TensionDocumentSchema as s, Tension as t, assertIsTensionState as u, createTension as v, DissolveTensionInputSchema as w, resolveTension as x, creators_exports as y };

//# sourceMappingURL=module-Dv-oA2vt.js.map