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/expense-report/v1/gen/document-model.ts
const documentModel = {
	id: "powerhouse/expense-report",
	name: "ExpenseReport",
	author: {
		name: "Powerhouse",
		website: "https://powerhouse.inc"
	},
	extension: "",
	description: "A document that contains expenses for n amount wallets across different dimensions, such as expense types and categories",
	specifications: [{
		state: {
			local: {
				schema: "",
				examples: [],
				initialValue: ""
			},
			global: {
				schema: "type ExpenseReportState {\n  ownerId: PHID\n  status: ExpenseReportStatus!\n  wallets: [Wallet!]!\n  groups: [LineItemGroup!]!\n  periodStart: DateTime\n  periodEnd: DateTime\n  startDate: DateTime\n  endDate: DateTime\n}\n\nenum ExpenseReportStatus {\n  DRAFT\n  REVIEW\n  FINAL\n}\n\ntype Wallet {\n  name: String\n  wallet: EthereumAddress\n  totals: [GroupTotals]\n  billingStatements: [OID]\n  lineItems: [LineItem]\n  accountDocumentId: PHID\n  accountTransactionsDocumentId: PHID\n}\n\ntype LineItemGroup {\n  id: ID!\n  label: String\n  parentId: ID\n}\n\ntype GroupTotals {\n  group: ID\n  totalBudget: Float\n  totalForecast: Float\n  totalActuals: Float\n  totalPayments: Float\n}\n\ntype LineItem {\n  id: ID\n  label: String\n  group: ID\n  budget: Float\n  actuals: Float\n  forecast: Float\n  payments: Float\n  comments: String\n}",
				examples: [],
				initialValue: "{\n  \"ownerId\": null,\n  \"status\": \"DRAFT\",\n  \"wallets\": [],\n  \"groups\": [\n    {\n      \"id\": \"57b0fdd7-51f5-4725-8a05-7ab3c15d90c2\",\n      \"label\": \"Headcount Expenses\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"4971def8-64f8-4eab-b69b-a869d10452c2\",\n      \"label\": \"Non-Headcount Expenses\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"e27b7f51-dc22-4ebe-8659-4e41824ae58c\",\n      \"label\": \"Travel & Entertainment\",\n      \"parentId\": \"57b0fdd7-51f5-4725-8a05-7ab3c15d90c2\"\n    },\n    {\n      \"id\": \"e4dce6df-1aa6-4861-b9f4-d861ad74d66c\",\n      \"label\": \"Compensation & Benefits\",\n      \"parentId\": \"57b0fdd7-51f5-4725-8a05-7ab3c15d90c2\"\n    },\n    {\n      \"id\": \"92e445ba-96af-4793-ae01-9b71035174ba\",\n      \"label\": \"Marketing Expense\",\n      \"parentId\": \"4971def8-64f8-4eab-b69b-a869d10452c2\"\n    },\n    {\n      \"id\": \"778dbd41-3d4a-4c8f-9004-7797f04e5b40\",\n      \"label\": \"Admin Expense\",\n      \"parentId\": \"4971def8-64f8-4eab-b69b-a869d10452c2\"\n    },\n    {\n      \"id\": \"5f024d53-7d0e-4818-9661-256aee69709d\",\n      \"label\": \"Professional Services\",\n      \"parentId\": \"4971def8-64f8-4eab-b69b-a869d10452c2\"\n    },\n    {\n      \"id\": \"659337f4-01c3-495a-89d7-c177c4137620\",\n      \"label\": \"Cost of Goods Sold\",\n      \"parentId\": \"4971def8-64f8-4eab-b69b-a869d10452c2\"\n    },\n    {\n      \"id\": \"1d6f0601-966a-4982-811d-981ac28db0b4\",\n      \"label\": \"Software Development Expense\",\n      \"parentId\": \"4971def8-64f8-4eab-b69b-a869d10452c2\"\n    },\n    {\n      \"id\": \"800dac9a-5665-4826-a972-b3170c789d92\",\n      \"label\": \"Income Tax Expense\",\n      \"parentId\": \"4971def8-64f8-4eab-b69b-a869d10452c2\"\n    },\n    {\n      \"id\": \"30ed3523-c15a-411f-a8f6-7bb6b978f6f8\",\n      \"label\": \"Software Expense\",\n      \"parentId\": \"4971def8-64f8-4eab-b69b-a869d10452c2\"\n    },\n    {\n      \"id\": \"ba7688ad-1329-4344-8f8a-e0f27dc648b8\",\n      \"label\": \"Gas Expense\",\n      \"parentId\": \"4971def8-64f8-4eab-b69b-a869d10452c2\"\n    },\n    {\n      \"id\": \"465367d1-636a-45a1-9e43-4a48dd074918\",\n      \"label\": \"Budget\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"aa5b7188-2231-445e-9f3d-7e5d1ce5754f\",\n      \"label\": \"Interest Income\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"d1e9bd15-930d-4faa-ba61-8f2a3b1d0e8f\",\n      \"label\": \"Other Income Expense (Non-operating)\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"133b762c-a240-4a42-8bf6-9c29b3675f91\",\n      \"label\": \"Other Income\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"1c61e841-c599-4c38-944a-7c9450c27d17\",\n      \"label\": \"Current Asset\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"5a33a954-09d0-4ddd-95fc-c56853de4dbd\",\n      \"label\": \"Fixed Asset\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"75130e59-7c11-44ae-980c-eaa4968a4a56\",\n      \"label\": \"Non-Current Asset\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"b3091879-f549-4227-beef-c8d4947be2e7\",\n      \"label\": \"Current Liability\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"2f64aca7-38db-4ff4-8cc5-8e0952c23151\",\n      \"label\": \"Non-current Liability\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"42e480eb-9790-49ed-af35-3ab124af556e\",\n      \"label\": \"Owner Equity\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"248f0af0-74b1-4fd9-9e7f-3d723f5c4c56\",\n      \"label\": \"Equity\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"5044752a-5618-4ab2-90b7-54b5d95e38cf\",\n      \"label\": \"Adjustment A/C\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"566fede7-b593-43d0-84b6-50301e5a84ed\",\n      \"label\": \"Temporary Holding Account\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"f0077e3f-2931-4637-8715-ba3a01ce3786\",\n      \"label\": \"Other\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"470504f0-a89f-4555-a46e-667c74240238\",\n      \"label\": \"Internal Transfers\",\n      \"parentId\": null\n    },\n    {\n      \"id\": \"121482a1-b69f-4511-g46f-267c24450238\",\n      \"label\": \"Uncategorized\",\n      \"parentId\": null\n    }\n  ],\n  \"periodStart\": null,\n  \"periodEnd\": null,\n  \"startDate\": null,\n  \"endDate\": null\n}"
			}
		},
		modules: [{
			id: "wallet",
			name: "wallet",
			operations: [
				{
					id: "add-wallet",
					name: "addWallet",
					scope: "global",
					errors: [],
					schema: "input AddWalletInput {\n  wallet: EthereumAddress!\n  name: String\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "remove-wallet",
					name: "removeWallet",
					scope: "global",
					errors: [],
					schema: "input RemoveWalletInput {\n  wallet: EthereumAddress!\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "add-billing-statement",
					name: "addBillingStatement",
					scope: "global",
					errors: [],
					schema: "input AddBillingStatementInput {\n  wallet: EthereumAddress!\n  billingStatementId: OID!\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "remove-billing-statement",
					name: "removeBillingStatement",
					scope: "global",
					errors: [],
					schema: "input RemoveBillingStatementInput {\n  wallet: EthereumAddress!\n  billingStatementId: OID!\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "add-line-item",
					name: "addLineItem",
					scope: "global",
					errors: [],
					schema: "input AddLineItemInput {\n  wallet: EthereumAddress!\n  lineItem: LineItemInput!\n}\n\ninput LineItemInput {\n  id: ID!\n  label: String\n  group: ID\n  budget: Float\n  actuals: Float\n  forecast: Float\n  payments: Float\n  comments: String\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "update-line-item",
					name: "updateLineItem",
					scope: "global",
					errors: [],
					schema: "input UpdateLineItemInput {\n  wallet: EthereumAddress!\n  lineItemId: ID!\n  label: String\n  group: ID\n  budget: Float\n  actuals: Float\n  forecast: Float\n  payments: Float\n  comments: String\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "remove-line-item",
					name: "removeLineItem",
					scope: "global",
					errors: [],
					schema: "input RemoveLineItemInput {\n  wallet: EthereumAddress!\n  lineItemId: ID!\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "add-line-item-group",
					name: "addLineItemGroup",
					scope: "global",
					errors: [],
					schema: "input AddLineItemGroupInput {\n  id: ID!\n  label: String\n  parentId: ID\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "update-line-item-group",
					name: "updateLineItemGroup",
					scope: "global",
					errors: [],
					schema: "input UpdateLineItemGroupInput {\n  id: ID!\n  label: String\n  parentId: ID\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "remove-line-item-group",
					name: "removeLineItemGroup",
					scope: "global",
					errors: [],
					schema: "input RemoveLineItemGroupInput {\n  id: ID!\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "set-group-totals",
					name: "setGroupTotals",
					scope: "global",
					errors: [],
					schema: "input SetGroupTotalsInput {\n  wallet: EthereumAddress!\n  groupTotals: GroupTotalsInput!\n}\n\ninput GroupTotalsInput {\n  group: ID!\n  totalBudget: Float\n  totalForecast: Float\n  totalActuals: Float\n  totalPayments: Float\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "remove-group-totals",
					name: "removeGroupTotals",
					scope: "global",
					errors: [],
					schema: "input RemoveGroupTotalsInput {\n  wallet: EthereumAddress!\n  groupId: ID!\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "set-period-start",
					name: "setPeriodStart",
					scope: "global",
					errors: [],
					schema: "input SetPeriodStartInput {\n  periodStart: DateTime!\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "set-period-end",
					name: "setPeriodEnd",
					scope: "global",
					errors: [],
					schema: "input SetPeriodEndInput {\n  periodEnd: DateTime!\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "update-wallet",
					name: "updateWallet",
					scope: "global",
					errors: [],
					schema: "input UpdateWalletInput {\n  address: EthereumAddress!\n  name: String\n  accountDocumentId: PHID\n  accountTransactionsDocumentId: PHID\n}",
					reducer: "const wallet = state.wallets.find((w) => w.wallet === action.input.address);\nif (!wallet) {\n  throw new Error(`Wallet with address ${action.input.address} not found`);\n}\n\nif (action.input.name !== undefined && action.input.name !== null) {\n  wallet.name = action.input.name;\n}\n\nif (action.input.accountDocumentId !== undefined && action.input.accountDocumentId !== null) {\n  wallet.accountDocumentId = action.input.accountDocumentId;\n}\n\nif (action.input.accountTransactionsDocumentId !== undefined && action.input.accountTransactionsDocumentId !== null) {\n  wallet.accountTransactionsDocumentId = action.input.accountTransactionsDocumentId;\n}",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "set-owner-id",
					name: "setOwnerId",
					scope: "global",
					errors: [],
					schema: "input SetOwnerIdInput {\n  ownerId: PHID!\n}",
					reducer: "state.ownerId = action.input.ownerId;",
					examples: [],
					template: "Set the owner ID (builder team) for the expense report",
					description: "Set the owner ID (builder team) for the expense report"
				},
				{
					id: "set-status",
					name: "setStatus",
					scope: "global",
					errors: [],
					schema: "input SetStatusInput {\n  status: ExpenseReportStatusInput!\n}\n\nenum ExpenseReportStatusInput {\n  DRAFT\n  REVIEW\n  FINAL\n}",
					reducer: "",
					examples: [],
					template: "",
					description: ""
				},
				{
					id: "set-period",
					name: "setPeriod",
					scope: "global",
					errors: [],
					schema: "input SetPeriodInput {\n  startDate: DateTime\n  endDate: DateTime\n}",
					reducer: "if (action.input.startDate !== undefined && action.input.startDate !== null) {\n  state.startDate = action.input.startDate;\n}\nif (action.input.endDate !== undefined && action.input.endDate !== null) {\n  state.endDate = action.input.endDate;\n}",
					examples: [],
					template: "Set the snapshot period dates for transaction filtering",
					description: "Set the snapshot period dates for transaction filtering"
				}
			],
			description: ""
		}],
		version: 1,
		changeLog: []
	}]
};
//#endregion
//#region document-models/expense-report/v1/src/reducers/wallet.ts
function getLineItemTotals(lineItem) {
	return {
		totalBudget: lineItem.budget ?? 0,
		totalForecast: lineItem.forecast ?? 0,
		totalActuals: lineItem.actuals ?? 0,
		totalPayments: lineItem.payments ?? 0
	};
}
function applyTotalsDelta(wallet, groupId, delta) {
	if (!groupId) return;
	if (!wallet.totals) wallet.totals = [];
	const existing = wallet.totals.find((t) => t && t.group === groupId) || null;
	if (existing) {
		existing.totalBudget = (existing.totalBudget ?? 0) + delta.totalBudget;
		existing.totalForecast = (existing.totalForecast ?? 0) + delta.totalForecast;
		existing.totalActuals = (existing.totalActuals ?? 0) + delta.totalActuals;
		existing.totalPayments = (existing.totalPayments ?? 0) + delta.totalPayments;
	} else wallet.totals.push({
		group: groupId,
		totalBudget: delta.totalBudget,
		totalForecast: delta.totalForecast,
		totalActuals: delta.totalActuals,
		totalPayments: delta.totalPayments
	});
}
const expenseReportWalletOperations = {
	addWalletOperation(state, action) {
		const newWallet = {
			name: action.input.name ?? null,
			wallet: action.input.wallet,
			totals: [],
			billingStatements: [],
			lineItems: [],
			accountDocumentId: null,
			accountTransactionsDocumentId: null
		};
		state.wallets.push(newWallet);
	},
	removeWalletOperation(state, action) {
		const index = state.wallets.findIndex((w) => w.wallet === action.input.wallet);
		if (index !== -1) state.wallets.splice(index, 1);
	},
	addBillingStatementOperation(state, action) {
		const wallet = state.wallets.find((w) => w.wallet === action.input.wallet);
		if (wallet) {
			if (!wallet.billingStatements) wallet.billingStatements = [];
			wallet.billingStatements.push(action.input.billingStatementId);
		}
	},
	removeBillingStatementOperation(state, action) {
		const wallet = state.wallets.find((w) => w.wallet === action.input.wallet);
		if (wallet && wallet.billingStatements) {
			const index = wallet.billingStatements.indexOf(action.input.billingStatementId);
			if (index !== -1) wallet.billingStatements.splice(index, 1);
		}
	},
	addLineItemOperation(state, action) {
		const wallet = state.wallets.find((w) => w.wallet === action.input.wallet);
		if (wallet) {
			if (!wallet.lineItems) wallet.lineItems = [];
			const lineItem = {
				id: action.input.lineItem.id,
				label: action.input.lineItem.label ?? null,
				group: action.input.lineItem.group ?? null,
				budget: action.input.lineItem.budget ?? null,
				actuals: action.input.lineItem.actuals ?? null,
				forecast: action.input.lineItem.forecast ?? null,
				payments: action.input.lineItem.payments ?? null,
				comments: action.input.lineItem.comments ?? null
			};
			wallet.lineItems.push(lineItem);
			applyTotalsDelta(wallet, lineItem.group, getLineItemTotals(lineItem));
		}
	},
	updateLineItemOperation(state, action) {
		const wallet = state.wallets.find((w) => w.wallet === action.input.wallet);
		if (wallet && wallet.lineItems) {
			const lineItem = wallet.lineItems.find((item) => item && item.id === action.input.lineItemId);
			if (lineItem) {
				const previousGroup = lineItem.group ?? null;
				const previousTotals = getLineItemTotals(lineItem);
				let nextGroup = previousGroup;
				const nextTotals = { ...previousTotals };
				if (action.input.label !== void 0 && action.input.label !== null) lineItem.label = action.input.label;
				if (action.input.group !== void 0 && action.input.group !== null) {
					lineItem.group = action.input.group;
					nextGroup = action.input.group;
				}
				if (action.input.budget !== void 0 && action.input.budget !== null) {
					lineItem.budget = action.input.budget;
					nextTotals.totalBudget = action.input.budget;
				}
				if (action.input.actuals !== void 0 && action.input.actuals !== null) {
					lineItem.actuals = action.input.actuals;
					nextTotals.totalActuals = action.input.actuals;
				}
				if (action.input.forecast !== void 0 && action.input.forecast !== null) {
					lineItem.forecast = action.input.forecast;
					nextTotals.totalForecast = action.input.forecast;
				}
				if (action.input.payments !== void 0) {
					lineItem.payments = action.input.payments ?? null;
					nextTotals.totalPayments = action.input.payments ?? 0;
				}
				if (action.input.comments !== void 0 && action.input.comments !== null) lineItem.comments = action.input.comments;
				if (previousGroup === nextGroup) applyTotalsDelta(wallet, nextGroup, {
					totalBudget: nextTotals.totalBudget - previousTotals.totalBudget,
					totalForecast: nextTotals.totalForecast - previousTotals.totalForecast,
					totalActuals: nextTotals.totalActuals - previousTotals.totalActuals,
					totalPayments: nextTotals.totalPayments - previousTotals.totalPayments
				});
				else {
					applyTotalsDelta(wallet, previousGroup, {
						totalBudget: -previousTotals.totalBudget,
						totalForecast: -previousTotals.totalForecast,
						totalActuals: -previousTotals.totalActuals,
						totalPayments: -previousTotals.totalPayments
					});
					applyTotalsDelta(wallet, nextGroup, nextTotals);
				}
			}
		}
	},
	removeLineItemOperation(state, action) {
		const wallet = state.wallets.find((w) => w.wallet === action.input.wallet);
		if (wallet && wallet.lineItems) {
			const index = wallet.lineItems.findIndex((item) => item && item.id === action.input.lineItemId);
			if (index !== -1) wallet.lineItems.splice(index, 1);
		}
	},
	addLineItemGroupOperation(state, action) {
		const newGroup = {
			id: action.input.id,
			label: action.input.label || null,
			parentId: action.input.parentId || null
		};
		state.groups.push(newGroup);
	},
	updateLineItemGroupOperation(state, action) {
		const group = state.groups.find((g) => g.id === action.input.id);
		if (group) {
			if (action.input.label !== void 0 && action.input.label !== null) group.label = action.input.label;
			if (action.input.parentId !== void 0 && action.input.parentId !== null) group.parentId = action.input.parentId;
		}
	},
	removeLineItemGroupOperation(state, action) {
		const index = state.groups.findIndex((g) => g.id === action.input.id);
		if (index !== -1) state.groups.splice(index, 1);
	},
	setGroupTotalsOperation(state, action) {
		const wallet = state.wallets.find((w) => w.wallet === action.input.wallet);
		if (wallet) {
			if (!wallet.totals) wallet.totals = [];
			const existingIndex = wallet.totals.findIndex((t) => t && t.group === action.input.groupTotals.group);
			const totals = {
				group: action.input.groupTotals.group,
				totalBudget: action.input.groupTotals.totalBudget || null,
				totalForecast: action.input.groupTotals.totalForecast || null,
				totalActuals: action.input.groupTotals.totalActuals || null,
				totalPayments: action.input.groupTotals.totalPayments || null
			};
			if (existingIndex !== -1) wallet.totals[existingIndex] = totals;
			else wallet.totals.push(totals);
		}
	},
	removeGroupTotalsOperation(state, action) {
		const wallet = state.wallets.find((w) => w.wallet === action.input.wallet);
		if (wallet && wallet.totals) {
			const index = wallet.totals.findIndex((t) => t && t.group === action.input.groupId);
			if (index !== -1) wallet.totals.splice(index, 1);
		}
	},
	setPeriodStartOperation(state, action) {
		state.periodStart = action.input.periodStart;
	},
	setPeriodEndOperation(state, action) {
		state.periodEnd = action.input.periodEnd;
	},
	updateWalletOperation(state, action) {
		const wallet = state.wallets.find((w) => w.wallet === action.input.address);
		if (wallet) {
			if (action.input.name !== void 0 && action.input.name !== null) wallet.name = action.input.name;
			if (action.input.accountDocumentId !== void 0 && action.input.accountDocumentId !== null) wallet.accountDocumentId = action.input.accountDocumentId;
			if (action.input.accountTransactionsDocumentId !== void 0 && action.input.accountTransactionsDocumentId !== null) wallet.accountTransactionsDocumentId = action.input.accountTransactionsDocumentId;
		}
	},
	setOwnerIdOperation(state, action) {
		state.ownerId = action.input.ownerId;
	},
	setStatusOperation(state, action) {
		state.status = action.input.status;
	},
	setPeriodOperation(state, action) {
		if (action.input.startDate !== void 0 && action.input.startDate !== null) state.startDate = action.input.startDate;
		if (action.input.endDate !== void 0 && action.input.endDate !== null) state.endDate = action.input.endDate;
	}
};
//#endregion
//#region document-models/expense-report/v1/gen/schema/zod.ts
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
const definedNonNullAnySchema = any().refine((v) => isDefinedNonNullAny(v));
const ExpenseReportStatusSchema = _enum([
	"DRAFT",
	"FINAL",
	"REVIEW"
]);
const ExpenseReportStatusInputSchema = _enum([
	"DRAFT",
	"FINAL",
	"REVIEW"
]);
function AddBillingStatementInputSchema() {
	return object({
		billingStatementId: string(),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" })
	});
}
function AddLineItemGroupInputSchema() {
	return object({
		id: string(),
		label: string().nullish(),
		parentId: string().nullish()
	});
}
function AddLineItemInputSchema() {
	return object({
		lineItem: lazy(() => LineItemInputSchema()),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" })
	});
}
function AddWalletInputSchema() {
	return object({
		name: string().nullish(),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" })
	});
}
function ExpenseReportStateSchema() {
	return object({
		__typename: literal("ExpenseReportState").optional(),
		endDate: datetime().nullish(),
		groups: array(lazy(() => LineItemGroupSchema())),
		ownerId: string().nullish(),
		periodEnd: datetime().nullish(),
		periodStart: datetime().nullish(),
		startDate: datetime().nullish(),
		status: ExpenseReportStatusSchema,
		wallets: array(lazy(() => WalletSchema()))
	});
}
function GroupTotalsSchema() {
	return object({
		__typename: literal("GroupTotals").optional(),
		group: string().nullish(),
		totalActuals: number().nullish(),
		totalBudget: number().nullish(),
		totalForecast: number().nullish(),
		totalPayments: number().nullish()
	});
}
function GroupTotalsInputSchema() {
	return object({
		group: string(),
		totalActuals: number().nullish(),
		totalBudget: number().nullish(),
		totalForecast: number().nullish(),
		totalPayments: number().nullish()
	});
}
function LineItemSchema() {
	return object({
		__typename: literal("LineItem").optional(),
		actuals: number().nullish(),
		budget: number().nullish(),
		comments: string().nullish(),
		forecast: number().nullish(),
		group: string().nullish(),
		id: string().nullish(),
		label: string().nullish(),
		payments: number().nullish()
	});
}
function LineItemGroupSchema() {
	return object({
		__typename: literal("LineItemGroup").optional(),
		id: string(),
		label: string().nullish(),
		parentId: string().nullish()
	});
}
function LineItemInputSchema() {
	return object({
		actuals: number().nullish(),
		budget: number().nullish(),
		comments: string().nullish(),
		forecast: number().nullish(),
		group: string().nullish(),
		id: string(),
		label: string().nullish(),
		payments: number().nullish()
	});
}
function RemoveBillingStatementInputSchema() {
	return object({
		billingStatementId: string(),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" })
	});
}
function RemoveGroupTotalsInputSchema() {
	return object({
		groupId: string(),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" })
	});
}
function RemoveLineItemGroupInputSchema() {
	return object({ id: string() });
}
function RemoveLineItemInputSchema() {
	return object({
		lineItemId: string(),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" })
	});
}
function RemoveWalletInputSchema() {
	return object({ wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" }) });
}
function SetGroupTotalsInputSchema() {
	return object({
		groupTotals: lazy(() => GroupTotalsInputSchema()),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" })
	});
}
function SetOwnerIdInputSchema() {
	return object({ ownerId: string() });
}
function SetPeriodEndInputSchema() {
	return object({ periodEnd: datetime() });
}
function SetPeriodInputSchema() {
	return object({
		endDate: datetime().nullish(),
		startDate: datetime().nullish()
	});
}
function SetPeriodStartInputSchema() {
	return object({ periodStart: datetime() });
}
function SetStatusInputSchema() {
	return object({ status: ExpenseReportStatusInputSchema });
}
function UpdateLineItemGroupInputSchema() {
	return object({
		id: string(),
		label: string().nullish(),
		parentId: string().nullish()
	});
}
function UpdateLineItemInputSchema() {
	return object({
		actuals: number().nullish(),
		budget: number().nullish(),
		comments: string().nullish(),
		forecast: number().nullish(),
		group: string().nullish(),
		label: string().nullish(),
		lineItemId: string(),
		payments: number().nullish(),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" })
	});
}
function UpdateWalletInputSchema() {
	return object({
		accountDocumentId: string().nullish(),
		accountTransactionsDocumentId: string().nullish(),
		address: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" }),
		name: string().nullish()
	});
}
function WalletSchema() {
	return object({
		__typename: literal("Wallet").optional(),
		accountDocumentId: string().nullish(),
		accountTransactionsDocumentId: string().nullish(),
		billingStatements: array(string().nullable()).nullish(),
		lineItems: array(lazy(() => LineItemSchema().nullable())).nullish(),
		name: string().nullish(),
		totals: array(lazy(() => GroupTotalsSchema().nullable())).nullish(),
		wallet: string().regex(/^0x[a-fA-F0-9]{40}$/, { message: "Invalid Ethereum address format" }).nullish()
	});
}
//#endregion
//#region document-models/expense-report/v1/gen/reducer.ts
const stateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	switch (action.type) {
		case "ADD_WALLET":
			AddWalletInputSchema().parse(action.input);
			expenseReportWalletOperations.addWalletOperation(state[action.scope], action, dispatch);
			break;
		case "REMOVE_WALLET":
			RemoveWalletInputSchema().parse(action.input);
			expenseReportWalletOperations.removeWalletOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_BILLING_STATEMENT":
			AddBillingStatementInputSchema().parse(action.input);
			expenseReportWalletOperations.addBillingStatementOperation(state[action.scope], action, dispatch);
			break;
		case "REMOVE_BILLING_STATEMENT":
			RemoveBillingStatementInputSchema().parse(action.input);
			expenseReportWalletOperations.removeBillingStatementOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_LINE_ITEM":
			AddLineItemInputSchema().parse(action.input);
			expenseReportWalletOperations.addLineItemOperation(state[action.scope], action, dispatch);
			break;
		case "UPDATE_LINE_ITEM":
			UpdateLineItemInputSchema().parse(action.input);
			expenseReportWalletOperations.updateLineItemOperation(state[action.scope], action, dispatch);
			break;
		case "REMOVE_LINE_ITEM":
			RemoveLineItemInputSchema().parse(action.input);
			expenseReportWalletOperations.removeLineItemOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_LINE_ITEM_GROUP":
			AddLineItemGroupInputSchema().parse(action.input);
			expenseReportWalletOperations.addLineItemGroupOperation(state[action.scope], action, dispatch);
			break;
		case "UPDATE_LINE_ITEM_GROUP":
			UpdateLineItemGroupInputSchema().parse(action.input);
			expenseReportWalletOperations.updateLineItemGroupOperation(state[action.scope], action, dispatch);
			break;
		case "REMOVE_LINE_ITEM_GROUP":
			RemoveLineItemGroupInputSchema().parse(action.input);
			expenseReportWalletOperations.removeLineItemGroupOperation(state[action.scope], action, dispatch);
			break;
		case "SET_GROUP_TOTALS":
			SetGroupTotalsInputSchema().parse(action.input);
			expenseReportWalletOperations.setGroupTotalsOperation(state[action.scope], action, dispatch);
			break;
		case "REMOVE_GROUP_TOTALS":
			RemoveGroupTotalsInputSchema().parse(action.input);
			expenseReportWalletOperations.removeGroupTotalsOperation(state[action.scope], action, dispatch);
			break;
		case "SET_PERIOD_START":
			SetPeriodStartInputSchema().parse(action.input);
			expenseReportWalletOperations.setPeriodStartOperation(state[action.scope], action, dispatch);
			break;
		case "SET_PERIOD_END":
			SetPeriodEndInputSchema().parse(action.input);
			expenseReportWalletOperations.setPeriodEndOperation(state[action.scope], action, dispatch);
			break;
		case "UPDATE_WALLET":
			UpdateWalletInputSchema().parse(action.input);
			expenseReportWalletOperations.updateWalletOperation(state[action.scope], action, dispatch);
			break;
		case "SET_OWNER_ID":
			SetOwnerIdInputSchema().parse(action.input);
			expenseReportWalletOperations.setOwnerIdOperation(state[action.scope], action, dispatch);
			break;
		case "SET_STATUS":
			SetStatusInputSchema().parse(action.input);
			expenseReportWalletOperations.setStatusOperation(state[action.scope], action, dispatch);
			break;
		case "SET_PERIOD":
			SetPeriodInputSchema().parse(action.input);
			expenseReportWalletOperations.setPeriodOperation(state[action.scope], action, dispatch);
			break;
		default: return state;
	}
};
const reducer = createReducer(stateReducer);
//#endregion
//#region document-models/expense-report/v1/gen/wallet/creators.ts
var creators_exports = /* @__PURE__ */ __exportAll({
	addBillingStatement: () => addBillingStatement,
	addLineItem: () => addLineItem,
	addLineItemGroup: () => addLineItemGroup,
	addWallet: () => addWallet,
	removeBillingStatement: () => removeBillingStatement,
	removeGroupTotals: () => removeGroupTotals,
	removeLineItem: () => removeLineItem,
	removeLineItemGroup: () => removeLineItemGroup,
	removeWallet: () => removeWallet,
	setGroupTotals: () => setGroupTotals,
	setOwnerId: () => setOwnerId,
	setPeriod: () => setPeriod,
	setPeriodEnd: () => setPeriodEnd,
	setPeriodStart: () => setPeriodStart,
	setStatus: () => setStatus,
	updateLineItem: () => updateLineItem,
	updateLineItemGroup: () => updateLineItemGroup,
	updateWallet: () => updateWallet
});
const addWallet = (input) => createAction("ADD_WALLET", { ...input }, void 0, AddWalletInputSchema, "global");
const removeWallet = (input) => createAction("REMOVE_WALLET", { ...input }, void 0, RemoveWalletInputSchema, "global");
const addBillingStatement = (input) => createAction("ADD_BILLING_STATEMENT", { ...input }, void 0, AddBillingStatementInputSchema, "global");
const removeBillingStatement = (input) => createAction("REMOVE_BILLING_STATEMENT", { ...input }, void 0, RemoveBillingStatementInputSchema, "global");
const addLineItem = (input) => createAction("ADD_LINE_ITEM", { ...input }, void 0, AddLineItemInputSchema, "global");
const updateLineItem = (input) => createAction("UPDATE_LINE_ITEM", { ...input }, void 0, UpdateLineItemInputSchema, "global");
const removeLineItem = (input) => createAction("REMOVE_LINE_ITEM", { ...input }, void 0, RemoveLineItemInputSchema, "global");
const addLineItemGroup = (input) => createAction("ADD_LINE_ITEM_GROUP", { ...input }, void 0, AddLineItemGroupInputSchema, "global");
const updateLineItemGroup = (input) => createAction("UPDATE_LINE_ITEM_GROUP", { ...input }, void 0, UpdateLineItemGroupInputSchema, "global");
const removeLineItemGroup = (input) => createAction("REMOVE_LINE_ITEM_GROUP", { ...input }, void 0, RemoveLineItemGroupInputSchema, "global");
const setGroupTotals = (input) => createAction("SET_GROUP_TOTALS", { ...input }, void 0, SetGroupTotalsInputSchema, "global");
const removeGroupTotals = (input) => createAction("REMOVE_GROUP_TOTALS", { ...input }, void 0, RemoveGroupTotalsInputSchema, "global");
const setPeriodStart = (input) => createAction("SET_PERIOD_START", { ...input }, void 0, SetPeriodStartInputSchema, "global");
const setPeriodEnd = (input) => createAction("SET_PERIOD_END", { ...input }, void 0, SetPeriodEndInputSchema, "global");
const updateWallet = (input) => createAction("UPDATE_WALLET", { ...input }, void 0, UpdateWalletInputSchema, "global");
const setOwnerId = (input) => createAction("SET_OWNER_ID", { ...input }, void 0, SetOwnerIdInputSchema, "global");
const setStatus = (input) => createAction("SET_STATUS", { ...input }, void 0, SetStatusInputSchema, "global");
const setPeriod = (input) => createAction("SET_PERIOD", { ...input }, void 0, SetPeriodInputSchema, "global");
//#endregion
//#region document-models/expense-report/v1/actions.ts
/** Actions for the ExpenseReport document model */
const actions = {
	...baseActions,
	...creators_exports
};
//#endregion
//#region document-models/expense-report/v1/gen/document-type.ts
const expenseReportDocumentType = "powerhouse/expense-report";
//#endregion
//#region document-models/expense-report/v1/gen/document-schema.ts
/** Schema for validating the header object of a ExpenseReport document */
const ExpenseReportDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal(expenseReportDocumentType) });
/** Schema for validating the state object of a ExpenseReport document */
const ExpenseReportPHStateSchema = BaseDocumentStateSchema.extend({ global: ExpenseReportStateSchema() });
const ExpenseReportDocumentSchema = object({
	header: ExpenseReportDocumentHeaderSchema,
	state: ExpenseReportPHStateSchema,
	initialState: ExpenseReportPHStateSchema
});
/** Simple helper function to check if a state object is a ExpenseReport document state object */
function isExpenseReportState(state) {
	return ExpenseReportPHStateSchema.safeParse(state).success;
}
/** Simple helper function to assert that a document state object is a ExpenseReport document state object */
function assertIsExpenseReportState(state) {
	ExpenseReportPHStateSchema.parse(state);
}
/** Simple helper function to check if a document is a ExpenseReport document */
function isExpenseReportDocument(document) {
	return ExpenseReportDocumentSchema.safeParse(document).success;
}
/** Simple helper function to assert that a document is a ExpenseReport document */
function assertIsExpenseReportDocument(document) {
	ExpenseReportDocumentSchema.parse(document);
}
//#endregion
//#region document-models/expense-report/v1/gen/utils.ts
const initialGlobalState = {
	ownerId: null,
	status: "DRAFT",
	wallets: [],
	groups: [
		{
			id: "57b0fdd7-51f5-4725-8a05-7ab3c15d90c2",
			label: "Headcount Expenses",
			parentId: null
		},
		{
			id: "4971def8-64f8-4eab-b69b-a869d10452c2",
			label: "Non-Headcount Expenses",
			parentId: null
		},
		{
			id: "e27b7f51-dc22-4ebe-8659-4e41824ae58c",
			label: "Travel & Entertainment",
			parentId: "57b0fdd7-51f5-4725-8a05-7ab3c15d90c2"
		},
		{
			id: "e4dce6df-1aa6-4861-b9f4-d861ad74d66c",
			label: "Compensation & Benefits",
			parentId: "57b0fdd7-51f5-4725-8a05-7ab3c15d90c2"
		},
		{
			id: "92e445ba-96af-4793-ae01-9b71035174ba",
			label: "Marketing Expense",
			parentId: "4971def8-64f8-4eab-b69b-a869d10452c2"
		},
		{
			id: "778dbd41-3d4a-4c8f-9004-7797f04e5b40",
			label: "Admin Expense",
			parentId: "4971def8-64f8-4eab-b69b-a869d10452c2"
		},
		{
			id: "5f024d53-7d0e-4818-9661-256aee69709d",
			label: "Professional Services",
			parentId: "4971def8-64f8-4eab-b69b-a869d10452c2"
		},
		{
			id: "659337f4-01c3-495a-89d7-c177c4137620",
			label: "Cost of Goods Sold",
			parentId: "4971def8-64f8-4eab-b69b-a869d10452c2"
		},
		{
			id: "1d6f0601-966a-4982-811d-981ac28db0b4",
			label: "Software Development Expense",
			parentId: "4971def8-64f8-4eab-b69b-a869d10452c2"
		},
		{
			id: "800dac9a-5665-4826-a972-b3170c789d92",
			label: "Income Tax Expense",
			parentId: "4971def8-64f8-4eab-b69b-a869d10452c2"
		},
		{
			id: "30ed3523-c15a-411f-a8f6-7bb6b978f6f8",
			label: "Software Expense",
			parentId: "4971def8-64f8-4eab-b69b-a869d10452c2"
		},
		{
			id: "ba7688ad-1329-4344-8f8a-e0f27dc648b8",
			label: "Gas Expense",
			parentId: "4971def8-64f8-4eab-b69b-a869d10452c2"
		},
		{
			id: "465367d1-636a-45a1-9e43-4a48dd074918",
			label: "Budget",
			parentId: null
		},
		{
			id: "aa5b7188-2231-445e-9f3d-7e5d1ce5754f",
			label: "Interest Income",
			parentId: null
		},
		{
			id: "d1e9bd15-930d-4faa-ba61-8f2a3b1d0e8f",
			label: "Other Income Expense (Non-operating)",
			parentId: null
		},
		{
			id: "133b762c-a240-4a42-8bf6-9c29b3675f91",
			label: "Other Income",
			parentId: null
		},
		{
			id: "1c61e841-c599-4c38-944a-7c9450c27d17",
			label: "Current Asset",
			parentId: null
		},
		{
			id: "5a33a954-09d0-4ddd-95fc-c56853de4dbd",
			label: "Fixed Asset",
			parentId: null
		},
		{
			id: "75130e59-7c11-44ae-980c-eaa4968a4a56",
			label: "Non-Current Asset",
			parentId: null
		},
		{
			id: "b3091879-f549-4227-beef-c8d4947be2e7",
			label: "Current Liability",
			parentId: null
		},
		{
			id: "2f64aca7-38db-4ff4-8cc5-8e0952c23151",
			label: "Non-current Liability",
			parentId: null
		},
		{
			id: "42e480eb-9790-49ed-af35-3ab124af556e",
			label: "Owner Equity",
			parentId: null
		},
		{
			id: "248f0af0-74b1-4fd9-9e7f-3d723f5c4c56",
			label: "Equity",
			parentId: null
		},
		{
			id: "5044752a-5618-4ab2-90b7-54b5d95e38cf",
			label: "Adjustment A/C",
			parentId: null
		},
		{
			id: "566fede7-b593-43d0-84b6-50301e5a84ed",
			label: "Temporary Holding Account",
			parentId: null
		},
		{
			id: "f0077e3f-2931-4637-8715-ba3a01ce3786",
			label: "Other",
			parentId: null
		},
		{
			id: "470504f0-a89f-4555-a46e-667c74240238",
			label: "Internal Transfers",
			parentId: null
		},
		{
			id: "121482a1-b69f-4511-g46f-267c24450238",
			label: "Uncategorized",
			parentId: null
		}
	],
	periodStart: null,
	periodEnd: null,
	startDate: null,
	endDate: 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 = expenseReportDocumentType;
		document.header.id = generateId();
		return document;
	},
	saveToFileHandle(document, input) {
		return baseSaveToFileHandle(document, input);
	},
	loadFromInput(input) {
		return baseLoadFromInput(input, reducer);
	},
	isStateOfType(state) {
		return isExpenseReportState(state);
	},
	assertIsStateOfType(state) {
		return assertIsExpenseReportState(state);
	},
	isDocumentOfType(document) {
		return isExpenseReportDocument(document);
	},
	assertIsDocumentOfType(document) {
		return assertIsExpenseReportDocument(document);
	}
};
//#endregion
//#region document-models/expense-report/v1/src/utils.ts
var utils_exports = /* @__PURE__ */ __exportAll({});
//#endregion
//#region document-models/expense-report/v1/utils.ts
/** Utils for the ExpenseReport document model */
const utils = {
	...utils$1,
	...utils_exports
};
//#endregion
//#region document-models/expense-report/v1/module.ts
/** Document model module for the ExpenseReport document type */
const ExpenseReport = {
	version: 1,
	reducer,
	actions,
	utils,
	documentModel: createState(defaultBaseState(), documentModel)
};
//#endregion
export { SetOwnerIdInputSchema as $, setStatus as A, ExpenseReportStatusInputSchema as B, removeLineItemGroup as C, setPeriod as D, setOwnerId as E, AddBillingStatementInputSchema as F, LineItemInputSchema as G, GroupTotalsInputSchema as H, AddLineItemGroupInputSchema as I, RemoveGroupTotalsInputSchema as J, LineItemSchema as K, AddLineItemInputSchema as L, updateLineItemGroup as M, updateWallet as N, setPeriodEnd as O, reducer as P, SetGroupTotalsInputSchema as Q, AddWalletInputSchema as R, removeLineItem as S, setGroupTotals as T, GroupTotalsSchema as U, ExpenseReportStatusSchema as V, LineItemGroupSchema as W, RemoveLineItemInputSchema as X, RemoveLineItemGroupInputSchema as Y, RemoveWalletInputSchema as Z, addLineItemGroup as _, utils$1 as a, UpdateLineItemInputSchema as at, removeBillingStatement as b, ExpenseReportPHStateSchema as c, definedNonNullAnySchema as ct, isExpenseReportDocument as d, SetPeriodEndInputSchema as et, isExpenseReportState as f, addLineItem as g, addBillingStatement as h, initialLocalState as i, UpdateLineItemGroupInputSchema as it, updateLineItem as j, setPeriodStart as k, assertIsExpenseReportDocument as l, isDefinedNonNullAny as lt, actions as m, utils as n, SetPeriodStartInputSchema as nt, ExpenseReportDocumentHeaderSchema as o, UpdateWalletInputSchema as ot, expenseReportDocumentType as p, RemoveBillingStatementInputSchema as q, initialGlobalState as r, SetStatusInputSchema as rt, ExpenseReportDocumentSchema as s, WalletSchema as st, ExpenseReport as t, SetPeriodInputSchema as tt, assertIsExpenseReportState as u, documentModel as ut, addWallet as v, removeWallet as w, removeGroupTotals as x, creators_exports as y, ExpenseReportStateSchema as z };

//# sourceMappingURL=module-jjo7KF-t.js.map