import { r as __exportAll } from "./chunk-olfrzTEO.js";
import { B as lazy, H as number, I as _enum, J as datetime, L as any, R as array, U as object, V as literal, W as string, a as BaseDocumentHeaderSchema, b as generateId, c as baseCreateDocument, f as createAction, g as createState, h as createReducer, l as baseLoadFromInput, o as BaseDocumentStateSchema, s as baseActions, u as baseSaveToFileHandle, v as defaultBaseState, x as isDocumentAction } from "./dist-uUUuTqM0.js";
//#region document-models/billing-statement/v1/gen/document-model.ts
const documentModel = {
	id: "powerhouse/billing-statement",
	name: "BillingStatement",
	author: {
		name: "Powerhouse",
		website: "https://powerhouse.inc"
	},
	extension: "",
	description: "The Billing Statement Document Model captures a contributor's issued charges, with itemized line entries and auto-calculated totals in cash and POWT's",
	specifications: [{
		state: {
			local: {
				schema: "",
				examples: [],
				initialValue: ""
			},
			global: {
				schema: "type BillingStatementState {\n  contributor: PHID\n  dateIssued: DateTime!\n  dateDue: DateTime\n  lineItems: [BillingStatementLineItem!]!\n  status: BillingStatementStatus!\n  currency: String!\n  totalCash: Float!\n  totalPowt: Float!\n  notes: String\n}\n\ntype BillingStatementLineItem {\n  id: OID!\n  description: String!\n  quantity: Float!\n  unit: BillingStatementUnit!\n  unitPricePwt: Float!\n  unitPriceCash: Float!\n  totalPricePwt: Float!\n  totalPriceCash: Float!\n  lineItemTag: [BillingStatementTag!]!\n}\n\ntype BillingStatementTag {\n  dimension: String!\n  value: String!\n  label: String\n}\n\nenum BillingStatementStatus {\n  DRAFT\n  ISSUED\n  ACCEPTED\n  REJECTED\n  PAID\n}\n\nenum BillingStatementStatusInput {\n  DRAFT\n  ISSUED\n  ACCEPTED\n  REJECTED\n  PAID\n}\n\nenum BillingStatementUnit {\n  MINUTE\n  HOUR\n  DAY\n  UNIT\n}\n\nenum BillingStatementUnitInput {\n  MINUTE\n  HOUR\n  DAY\n  UNIT\n}",
				examples: [],
				initialValue: "{\"contributor\": null, \"dateIssued\": \"2025-06-10T15:42:17.873Z\", \"dateDue\": \"2025-06-10T15:42:17.873Z\", \"lineItems\": [], \"status\": \"DRAFT\", \"currency\": \"\", \"totalCash\": 0, \"totalPowt\": 0, \"notes\": \"\"}"
			}
		},
		modules: [
			{
				id: "general",
				name: "general",
				operations: [
					{
						id: "edit-billing-statement",
						name: "editBillingStatement",
						scope: "global",
						errors: [],
						schema: "input EditBillingStatementInput {\n  dateIssued: DateTime\n  dateDue: DateTime\n  currency: String\n  notes: String\n}",
						reducer: "",
						examples: [],
						template: "",
						description: ""
					},
					{
						id: "edit-contributor",
						name: "editContributor",
						scope: "global",
						errors: [],
						schema: "input EditContributorInput {\n  contributor: PHID!\n}",
						reducer: "",
						examples: [],
						template: "",
						description: ""
					},
					{
						id: "edit-status",
						name: "editStatus",
						scope: "global",
						errors: [],
						schema: "input EditStatusInput {\n  status: BillingStatementStatusInput!\n}",
						reducer: "",
						examples: [],
						template: "",
						description: ""
					}
				],
				description: ""
			},
			{
				id: "line-items",
				name: "line_items",
				operations: [
					{
						id: "add-line-item",
						name: "addLineItem",
						scope: "global",
						errors: [],
						schema: "input AddLineItemInput {\n  id: OID!\n  description: String!\n  quantity: Float!\n  unit: BillingStatementUnitInput!\n  unitPricePwt: Float!\n  unitPriceCash: Float!\n  totalPricePwt: Float!\n  totalPriceCash: Float!\n}",
						reducer: "",
						examples: [],
						template: "BillingStatementState.totalCash / .totalPowt will be a sum of the line item values.",
						description: "BillingStatementState.totalCash / .totalPowt will be a sum of the line item values."
					},
					{
						id: "edit-line-item",
						name: "editLineItem",
						scope: "global",
						errors: [],
						schema: "input EditLineItemInput {\n  id: OID!\n  description: String\n  quantity: Float\n  unit: BillingStatementUnitInput\n  unitPricePwt: Float\n  unitPriceCash: Float\n  totalPricePwt: Float\n  totalPriceCash: Float\n}",
						reducer: "",
						examples: [],
						template: "BillingStatementState.totalCash / .totalPowt will be a sum of the line item values.",
						description: "BillingStatementState.totalCash / .totalPowt will be a sum of the line item values."
					},
					{
						id: "delete-line-item",
						name: "deleteLineItem",
						scope: "global",
						errors: [],
						schema: "input DeleteLineItemInput {\n  id: OID!\n}",
						reducer: "",
						examples: [],
						template: "",
						description: ""
					}
				],
				description: ""
			},
			{
				id: "tags",
				name: "tags",
				operations: [{
					id: "edit-line-item-tag",
					name: "editLineItemTag",
					scope: "global",
					errors: [],
					schema: "input EditLineItemTagInput {\n  lineItemId: OID!\n  dimension: String!\n  value: String!\n  label: String\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				}],
				description: ""
			}
		],
		version: 1,
		changeLog: []
	}]
};
//#endregion
//#region document-models/billing-statement/v1/gen/schema/zod.ts
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
const definedNonNullAnySchema = any().refine((v) => isDefinedNonNullAny(v));
const BillingStatementStatusSchema = _enum([
	"ACCEPTED",
	"DRAFT",
	"ISSUED",
	"PAID",
	"REJECTED"
]);
const BillingStatementStatusInputSchema = _enum([
	"ACCEPTED",
	"DRAFT",
	"ISSUED",
	"PAID",
	"REJECTED"
]);
const BillingStatementUnitSchema = _enum([
	"DAY",
	"HOUR",
	"MINUTE",
	"UNIT"
]);
const BillingStatementUnitInputSchema = _enum([
	"DAY",
	"HOUR",
	"MINUTE",
	"UNIT"
]);
function AddLineItemInputSchema() {
	return object({
		description: string(),
		id: string(),
		quantity: number(),
		totalPriceCash: number(),
		totalPricePwt: number(),
		unit: BillingStatementUnitInputSchema,
		unitPriceCash: number(),
		unitPricePwt: number()
	});
}
function BillingStatementLineItemSchema() {
	return object({
		__typename: literal("BillingStatementLineItem").optional(),
		description: string(),
		id: string(),
		lineItemTag: array(lazy(() => BillingStatementTagSchema())),
		quantity: number(),
		totalPriceCash: number(),
		totalPricePwt: number(),
		unit: BillingStatementUnitSchema,
		unitPriceCash: number(),
		unitPricePwt: number()
	});
}
function BillingStatementStateSchema() {
	return object({
		__typename: literal("BillingStatementState").optional(),
		contributor: string().nullish(),
		currency: string(),
		dateDue: datetime().nullish(),
		dateIssued: datetime(),
		lineItems: array(lazy(() => BillingStatementLineItemSchema())),
		notes: string().nullish(),
		status: BillingStatementStatusSchema,
		totalCash: number(),
		totalPowt: number()
	});
}
function BillingStatementTagSchema() {
	return object({
		__typename: literal("BillingStatementTag").optional(),
		dimension: string(),
		label: string().nullish(),
		value: string()
	});
}
function DeleteLineItemInputSchema() {
	return object({ id: string() });
}
function EditBillingStatementInputSchema() {
	return object({
		currency: string().nullish(),
		dateDue: datetime().nullish(),
		dateIssued: datetime().nullish(),
		notes: string().nullish()
	});
}
function EditContributorInputSchema() {
	return object({ contributor: string() });
}
function EditLineItemInputSchema() {
	return object({
		description: string().nullish(),
		id: string(),
		quantity: number().nullish(),
		totalPriceCash: number().nullish(),
		totalPricePwt: number().nullish(),
		unit: BillingStatementUnitInputSchema.nullish(),
		unitPriceCash: number().nullish(),
		unitPricePwt: number().nullish()
	});
}
function EditLineItemTagInputSchema() {
	return object({
		dimension: string(),
		label: string().nullish(),
		lineItemId: string(),
		value: string()
	});
}
function EditStatusInputSchema() {
	return object({ status: BillingStatementStatusInputSchema });
}
//#endregion
//#region document-models/billing-statement/v1/src/reducers/general.ts
const billingStatementGeneralOperations = {
	editBillingStatementOperation(state, action) {
		state.dateIssued = action.input.dateIssued ?? state.dateIssued;
		state.dateDue = action.input.dateDue ?? state.dateDue;
		state.currency = action.input.currency ?? state.currency;
		state.notes = action.input.notes ?? state.notes;
	},
	editContributorOperation(state, action) {
		state.contributor = action.input.contributor ?? state.contributor;
	},
	editStatusOperation(state, action) {
		if (!BillingStatementStatusInputSchema.safeParse(action.input.status).success) throw new Error("Invalid status value");
		state.status = action.input.status ?? state.status;
	}
};
//#endregion
//#region document-models/billing-statement/v1/src/reducers/line-items.ts
const billingStatementLineItemsOperations = {
	addLineItemOperation(state, action) {
		const newLineItem = {
			...action.input,
			lineItemTag: []
		};
		if (state.lineItems.find((x) => x.id === newLineItem.id)) throw new Error("Duplicate line item ID");
		state.lineItems.push(newLineItem);
		updateTotals(state);
	},
	editLineItemOperation(state, action) {
		const stateItem = state.lineItems.find((x) => x.id === action.input.id);
		if (!stateItem) throw new Error("Item matching input.id not found");
		const sanitizedInput = Object.fromEntries(Object.entries(action.input).filter(([, value]) => value !== null));
		const nextItem = {
			...stateItem,
			...sanitizedInput
		};
		Object.assign(stateItem, nextItem);
		updateTotals(state);
	},
	deleteLineItemOperation(state, action) {
		state.lineItems = state.lineItems.filter((x) => x.id !== action.input.id);
		updateTotals(state);
	}
};
const updateTotals = (state) => {
	state.totalCash = state.lineItems.reduce((total, lineItem) => {
		return total + lineItem.quantity * lineItem.unitPriceCash;
	}, 0);
	state.totalPowt = state.lineItems.reduce((total, lineItem) => {
		return total + lineItem.quantity * lineItem.unitPricePwt;
	}, 0);
};
//#endregion
//#region document-models/billing-statement/v1/src/reducers/tags.ts
const billingStatementTagsOperations = { editLineItemTagOperation(state, action) {
	const stateItem = state.lineItems.find((x) => x.id === action.input.lineItemId);
	if (!stateItem) throw new Error("Item matching input.lineItemId not found");
	const existingTag = stateItem.lineItemTag?.find((tag) => tag.dimension === action.input.dimension);
	if (existingTag) {
		existingTag.value = action.input.value;
		existingTag.label = action.input.label || null;
	} else {
		const newTag = {
			dimension: action.input.dimension,
			value: action.input.value,
			label: action.input.label || null
		};
		if (!stateItem.lineItemTag) stateItem.lineItemTag = [];
		stateItem.lineItemTag?.push(newTag);
	}
} };
//#endregion
//#region document-models/billing-statement/v1/gen/reducer.ts
const stateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	switch (action.type) {
		case "EDIT_BILLING_STATEMENT":
			EditBillingStatementInputSchema().parse(action.input);
			billingStatementGeneralOperations.editBillingStatementOperation(state[action.scope], action, dispatch);
			break;
		case "EDIT_CONTRIBUTOR":
			EditContributorInputSchema().parse(action.input);
			billingStatementGeneralOperations.editContributorOperation(state[action.scope], action, dispatch);
			break;
		case "EDIT_STATUS":
			EditStatusInputSchema().parse(action.input);
			billingStatementGeneralOperations.editStatusOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_LINE_ITEM":
			AddLineItemInputSchema().parse(action.input);
			billingStatementLineItemsOperations.addLineItemOperation(state[action.scope], action, dispatch);
			break;
		case "EDIT_LINE_ITEM":
			EditLineItemInputSchema().parse(action.input);
			billingStatementLineItemsOperations.editLineItemOperation(state[action.scope], action, dispatch);
			break;
		case "DELETE_LINE_ITEM":
			DeleteLineItemInputSchema().parse(action.input);
			billingStatementLineItemsOperations.deleteLineItemOperation(state[action.scope], action, dispatch);
			break;
		case "EDIT_LINE_ITEM_TAG":
			EditLineItemTagInputSchema().parse(action.input);
			billingStatementTagsOperations.editLineItemTagOperation(state[action.scope], action, dispatch);
			break;
		default: return state;
	}
};
const reducer = createReducer(stateReducer);
//#endregion
//#region document-models/billing-statement/v1/gen/general/creators.ts
var creators_exports$2 = /* @__PURE__ */ __exportAll({
	editBillingStatement: () => editBillingStatement,
	editContributor: () => editContributor,
	editStatus: () => editStatus
});
const editBillingStatement = (input) => createAction("EDIT_BILLING_STATEMENT", { ...input }, void 0, EditBillingStatementInputSchema, "global");
const editContributor = (input) => createAction("EDIT_CONTRIBUTOR", { ...input }, void 0, EditContributorInputSchema, "global");
const editStatus = (input) => createAction("EDIT_STATUS", { ...input }, void 0, EditStatusInputSchema, "global");
//#endregion
//#region document-models/billing-statement/v1/gen/line-items/creators.ts
var creators_exports$1 = /* @__PURE__ */ __exportAll({
	addLineItem: () => addLineItem,
	deleteLineItem: () => deleteLineItem,
	editLineItem: () => editLineItem
});
const addLineItem = (input) => createAction("ADD_LINE_ITEM", { ...input }, void 0, AddLineItemInputSchema, "global");
const editLineItem = (input) => createAction("EDIT_LINE_ITEM", { ...input }, void 0, EditLineItemInputSchema, "global");
const deleteLineItem = (input) => createAction("DELETE_LINE_ITEM", { ...input }, void 0, DeleteLineItemInputSchema, "global");
//#endregion
//#region document-models/billing-statement/v1/gen/tags/creators.ts
var creators_exports = /* @__PURE__ */ __exportAll({ editLineItemTag: () => editLineItemTag });
const editLineItemTag = (input) => createAction("EDIT_LINE_ITEM_TAG", { ...input }, void 0, EditLineItemTagInputSchema, "global");
//#endregion
//#region document-models/billing-statement/v1/actions.ts
/** Actions for the BillingStatement document model */
const actions = {
	...baseActions,
	...creators_exports$2,
	...creators_exports$1,
	...creators_exports
};
//#endregion
//#region document-models/billing-statement/v1/gen/document-type.ts
const billingStatementDocumentType = "powerhouse/billing-statement";
//#endregion
//#region document-models/billing-statement/v1/gen/document-schema.ts
/** Schema for validating the header object of a BillingStatement document */
const BillingStatementDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal(billingStatementDocumentType) });
/** Schema for validating the state object of a BillingStatement document */
const BillingStatementPHStateSchema = BaseDocumentStateSchema.extend({ global: BillingStatementStateSchema() });
const BillingStatementDocumentSchema = object({
	header: BillingStatementDocumentHeaderSchema,
	state: BillingStatementPHStateSchema,
	initialState: BillingStatementPHStateSchema
});
/** Simple helper function to check if a state object is a BillingStatement document state object */
function isBillingStatementState(state) {
	return BillingStatementPHStateSchema.safeParse(state).success;
}
/** Simple helper function to assert that a document state object is a BillingStatement document state object */
function assertIsBillingStatementState(state) {
	BillingStatementPHStateSchema.parse(state);
}
/** Simple helper function to check if a document is a BillingStatement document */
function isBillingStatementDocument(document) {
	return BillingStatementDocumentSchema.safeParse(document).success;
}
/** Simple helper function to assert that a document is a BillingStatement document */
function assertIsBillingStatementDocument(document) {
	BillingStatementDocumentSchema.parse(document);
}
//#endregion
//#region document-models/billing-statement/v1/gen/utils.ts
const initialGlobalState = {
	contributor: null,
	dateIssued: "2025-06-10T15:42:17.873Z",
	dateDue: "2025-06-10T15:42:17.873Z",
	lineItems: [],
	status: "DRAFT",
	currency: "",
	totalCash: 0,
	totalPowt: 0,
	notes: ""
};
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 = billingStatementDocumentType;
		document.header.id = generateId();
		return document;
	},
	saveToFileHandle(document, input) {
		return baseSaveToFileHandle(document, input);
	},
	loadFromInput(input) {
		return baseLoadFromInput(input, reducer);
	},
	isStateOfType(state) {
		return isBillingStatementState(state);
	},
	assertIsStateOfType(state) {
		return assertIsBillingStatementState(state);
	},
	isDocumentOfType(document) {
		return isBillingStatementDocument(document);
	},
	assertIsDocumentOfType(document) {
		return assertIsBillingStatementDocument(document);
	}
};
//#endregion
//#region document-models/billing-statement/v1/src/utils.ts
var utils_exports = /* @__PURE__ */ __exportAll({});
//#endregion
//#region document-models/billing-statement/v1/utils.ts
/** Utils for the BillingStatement document model */
const utils = {
	...utils$1,
	...utils_exports
};
//#endregion
//#region document-models/billing-statement/v1/module.ts
/** Document model module for the BillingStatement document type */
const BillingStatement = {
	version: 1,
	reducer,
	actions,
	utils,
	documentModel: createState(defaultBaseState(), documentModel)
};
//#endregion
export { BillingStatementStatusSchema as A, definedNonNullAnySchema as B, editContributor as C, BillingStatementLineItemSchema as D, AddLineItemInputSchema as E, EditBillingStatementInputSchema as F, documentModel as H, EditContributorInputSchema as I, EditLineItemInputSchema as L, BillingStatementUnitInputSchema as M, BillingStatementUnitSchema as N, BillingStatementStateSchema as O, DeleteLineItemInputSchema as P, EditLineItemTagInputSchema as R, editBillingStatement as S, reducer as T, isDefinedNonNullAny as V, addLineItem as _, utils$1 as a, editLineItem as b, BillingStatementPHStateSchema as c, isBillingStatementDocument as d, isBillingStatementState as f, editLineItemTag as g, creators_exports as h, initialLocalState as i, BillingStatementTagSchema as j, BillingStatementStatusInputSchema as k, assertIsBillingStatementDocument as l, actions as m, utils as n, BillingStatementDocumentHeaderSchema as o, billingStatementDocumentType as p, initialGlobalState as r, BillingStatementDocumentSchema as s, BillingStatement as t, assertIsBillingStatementState as u, creators_exports$1 as v, editStatus as w, creators_exports$2 as x, deleteLineItem as y, EditStatusInputSchema as z };

//# sourceMappingURL=module-CwMGazRD.js.map