import { r as __exportAll } from "./chunk-olfrzTEO.js";
import { U as object, V as literal, a as BaseDocumentHeaderSchema, b as generateId, c as baseCreateDocument, 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";
import { E as UpdateTransactionPeriodInputSchema, T as UpdateTransactionInputSchema, _ as DeleteBudgetInputSchema, h as AddTransactionInputSchema, m as AddBudgetInputSchema, n as creators_exports$2, o as creators_exports$1, p as AccountTransactionsStateSchema, u as creators_exports, v as DeleteTransactionInputSchema, w as UpdateBudgetInputSchema, y as SetAccountInputSchema } from "./creators-1UUtt16O.js";
//#region document-models/account-transactions/v1/gen/document-model.ts
const documentModel = {
	id: "powerhouse/account-transactions",
	name: "AccountTransactions",
	author: {
		name: "Powerhouse",
		website: "https://powerhouse.inc"
	},
	extension: "",
	description: "The AccountTransactions doc model is designed to track and manage all transactions associated with various accounts. Each transaction entry records critical details such as the source and destination accounts, transaction amount, timestamp, and specific transaction details tailored to the type of transaction (e.g., cryptocurrency or bank-related).",
	specifications: [{
		state: {
			local: {
				schema: "",
				examples: [],
				initialValue: ""
			},
			global: {
				schema: "type AccountTransactionsState {\n  account: Account!\n  transactions: [TransactionEntry!]!\n  budgets: [Budget!]!\n}\n\ntype Account {\n    id: OID!\n    account: String!\n    name: String!\n    budgetPath: String\n    accountTransactionsId: PHID\n    chain: [String!]\n    type: String\n    owners: [String!]\n    KycAmlStatus: String\n}\n\ntype TransactionDetails {\n    txHash: String!\n    token: Currency!\n    blockNumber: Int\n    uniqueId: String\n}\n\ntype TransactionEntry {\n    id: ID!\n    counterParty: EthereumAddress\n    amount: Amount_Currency!\n    datetime: DateTime!\n    details: TransactionDetails!\n    budget: OID\n    accountingPeriod: String!\n    direction: TransactionDirection!\n}\n\ntype Budget {\n    id: OID!\n    name: OLabel\n}\n\nenum TransactionDirection {\n    INFLOW\n    OUTFLOW\n}\n\nenum TransactionDirectionInput {\n    INFLOW\n    OUTFLOW\n}",
				examples: [],
				initialValue: "{\"account\":{\"id\":\"\",\"account\":\"\",\"name\":\"\",\"budgetPath\":null,\"accountTransactionsId\":null,\"chain\":null,\"type\":null,\"owners\":null,\"KycAmlStatus\":null},\"transactions\":[],\"budgets\":[]}"
			}
		},
		modules: [
			{
				id: "account-module-id",
				name: "account",
				operations: [{
					id: "set-account-op-id",
					name: "SET_ACCOUNT",
					scope: "global",
					errors: [],
					schema: "input SetAccountInput {\n    id: OID!\n    account: String!\n    name: String!\n    budgetPath: String\n    accountTransactionsId: PHID\n    chain: [String!]\n    type: String\n    owners: [String!]\n    KycAmlStatus: String\n}",
					reducer: "state.account.account = action.input.account;\nstate.account.name = action.input.name;\nstate.account.budgetPath = action.input.budgetPath || null;\nstate.account.accountTransactionsId = action.input.accountTransactionsId || null;\nstate.account.chain = action.input.chain || null;\nstate.account.type = action.input.type || null;\nstate.account.owners = action.input.owners || null;\nstate.account.KycAmlStatus = action.input.KycAmlStatus || null;",
					examples: [],
					template: "",
					description: ""
				}],
				description: ""
			},
			{
				id: "transactions-module-id",
				name: "transactions",
				operations: [
					{
						id: "add-transaction-op-id",
						name: "ADD_TRANSACTION",
						scope: "global",
						errors: [],
						schema: "input AddTransactionInput {\n    id: ID!\n    counterParty: EthereumAddress\n    amount: Amount_Currency!\n    datetime: DateTime!\n    txHash: String!\n    token: Currency!\n    blockNumber: Int\n    uniqueId: String\n    budget: OID\n    accountingPeriod: String!\n    direction: TransactionDirectionInput!\n}",
						reducer: "// Check for duplicate uniqueId to prevent duplicate transactions\nif (action.input.uniqueId) {\n  const existingTransaction = state.transactions.find(\n    (tx) => tx.details.uniqueId === action.input.uniqueId,\n  );\n  if (existingTransaction) {\n    throw new Error(\n      `Transaction with uniqueId ${action.input.uniqueId} already exists`,\n    );\n  }\n}\n\nstate.transactions.push({\n  id: action.input.id,\n  counterParty: action.input.counterParty || null,\n  amount: action.input.amount,\n  datetime: action.input.datetime,\n  details: {\n    txHash: action.input.txHash,\n    token: action.input.token,\n    blockNumber: action.input.blockNumber || null,\n    uniqueId: action.input.uniqueId || null,\n  },\n  budget: action.input.budget || null,\n  accountingPeriod: action.input.accountingPeriod,\n  direction: action.input.direction,\n});",
						examples: [],
						template: "",
						description: ""
					},
					{
						id: "update-transaction-op-id",
						name: "UPDATE_TRANSACTION",
						scope: "global",
						errors: [],
						schema: "input UpdateTransactionInput {\n    id: ID!\n    counterParty: EthereumAddress\n    amount: Amount_Currency\n    datetime: DateTime\n    txHash: String\n    token: Currency\n    blockNumber: Int\n    uniqueId: String\n    budget: OID\n    accountingPeriod: String\n    direction: TransactionDirectionInput\n}",
						reducer: "const transaction = state.transactions.find(\n  (transaction) => transaction.id === action.input.id,\n);\nif (!transaction) {\n  throw new Error(`Transaction with id ${action.input.id} not found`);\n}\nif (\n  action.input.counterParty !== undefined &&\n  action.input.counterParty !== null\n) {\n  transaction.counterParty = action.input.counterParty;\n}\nif (action.input.amount !== undefined && action.input.amount !== null) {\n  transaction.amount = action.input.amount;\n}\nif (\n  action.input.datetime !== undefined &&\n  action.input.datetime !== null\n) {\n  transaction.datetime = action.input.datetime;\n}\nif (action.input.txHash !== undefined && action.input.txHash !== null) {\n  transaction.details.txHash = action.input.txHash;\n}\nif (action.input.token !== undefined && action.input.token !== null) {\n  transaction.details.token = action.input.token;\n}\nif (action.input.blockNumber !== undefined) {\n  transaction.details.blockNumber = action.input.blockNumber;\n}\nif (action.input.uniqueId !== undefined) {\n  transaction.details.uniqueId = action.input.uniqueId;\n}\nif (\n  action.input.direction !== undefined &&\n  action.input.direction !== null\n) {\n  transaction.direction = action.input.direction;\n}",
						examples: [],
						template: "",
						description: ""
					},
					{
						id: "delete-transaction-op-id",
						name: "DELETE_TRANSACTION",
						scope: "global",
						errors: [],
						schema: "input DeleteTransactionInput {\n    id: ID!\n}",
						reducer: "state.transactions = state.transactions.filter(\n  (transaction) => transaction.id !== action.input.id,\n);",
						examples: [],
						template: "",
						description: ""
					},
					{
						id: "update-period-op-id",
						name: "UPDATE_TRANSACTION_PERIOD",
						scope: "global",
						errors: [],
						schema: "input UpdateTransactionPeriodInput {\n    id: ID!\n    accountingPeriod: String!\n}",
						reducer: "const transaction = state.transactions.find(\n  (transaction) => transaction.id === action.input.id,\n);\nif (!transaction) {\n  throw new Error(`Transaction with id ${action.input.id} not found`);\n}\ntransaction.accountingPeriod = action.input.accountingPeriod || \"\";",
						examples: [],
						template: "",
						description: ""
					}
				],
				description: ""
			},
			{
				id: "budgets-module-id",
				name: "budgets",
				operations: [
					{
						id: "add-budget-op-id",
						name: "ADD_BUDGET",
						scope: "global",
						errors: [],
						schema: "input AddBudgetInput {\n    id: OID!\n    name: OLabel\n}",
						reducer: "state.budgets.push({\n  id: action.input.id,\n  name: action.input.name || null,\n});",
						examples: [],
						template: "",
						description: ""
					},
					{
						id: "update-budget-op-id",
						name: "UPDATE_BUDGET",
						scope: "global",
						errors: [],
						schema: "input UpdateBudgetInput {\n    id: OID!\n    name: OLabel\n}",
						reducer: "const budget = state.budgets.find(\n  (budget) => budget.id === action.input.id,\n);\nif (!budget) {\n  throw new Error(`Budget with id ${action.input.id} not found`);\n}\nif (action.input.name !== undefined && action.input.name !== null) {\n  budget.name = action.input.name;\n}",
						examples: [],
						template: "",
						description: ""
					},
					{
						id: "delete-budget-op-id",
						name: "DELETE_BUDGET",
						scope: "global",
						errors: [],
						schema: "input DeleteBudgetInput {\n    id: OID!\n}",
						reducer: "state.budgets = state.budgets.filter(\n  (budget) => budget.id !== action.input.id,\n);",
						examples: [],
						template: "",
						description: ""
					}
				],
				description: ""
			}
		],
		version: 1,
		changeLog: []
	}]
};
//#endregion
//#region document-models/account-transactions/v1/src/reducers/account.ts
const accountTransactionsAccountOperations = { setAccountOperation(state, action) {
	state.account.account = action.input.account;
	state.account.name = action.input.name;
	state.account.budgetPath = action.input.budgetPath || null;
	state.account.accountTransactionsId = action.input.accountTransactionsId || null;
	state.account.chain = action.input.chain || null;
	state.account.type = action.input.type || null;
	state.account.owners = action.input.owners || null;
	state.account.KycAmlStatus = action.input.KycAmlStatus || null;
} };
//#endregion
//#region document-models/account-transactions/v1/src/reducers/transactions.ts
const accountTransactionsTransactionsOperations = {
	addTransactionOperation(state, action) {
		if (action.input.uniqueId) {
			if (state.transactions.find((tx) => tx.details.uniqueId === action.input.uniqueId)) throw new Error(`Transaction with uniqueId ${action.input.uniqueId} already exists`);
		}
		state.transactions.push({
			id: action.input.id,
			counterParty: action.input.counterParty || null,
			amount: action.input.amount,
			datetime: action.input.datetime,
			details: {
				txHash: action.input.txHash,
				token: action.input.token,
				blockNumber: action.input.blockNumber || null,
				uniqueId: action.input.uniqueId || null
			},
			budget: action.input.budget || null,
			accountingPeriod: action.input.accountingPeriod,
			direction: action.input.direction
		});
	},
	updateTransactionOperation(state, action) {
		const transaction = state.transactions.find((transaction) => transaction.id === action.input.id);
		if (!transaction) throw new Error(`Transaction with id ${action.input.id} not found`);
		if (action.input.counterParty !== void 0 && action.input.counterParty !== null) transaction.counterParty = action.input.counterParty;
		if (action.input.amount !== void 0 && action.input.amount !== null) transaction.amount = action.input.amount;
		if (action.input.datetime !== void 0 && action.input.datetime !== null) transaction.datetime = action.input.datetime;
		if (action.input.txHash !== void 0 && action.input.txHash !== null) transaction.details.txHash = action.input.txHash;
		if (action.input.token !== void 0 && action.input.token !== null) transaction.details.token = action.input.token;
		if (action.input.blockNumber !== void 0) transaction.details.blockNumber = action.input.blockNumber;
		if (action.input.uniqueId !== void 0) transaction.details.uniqueId = action.input.uniqueId;
		if (action.input.direction !== void 0 && action.input.direction !== null) transaction.direction = action.input.direction;
	},
	deleteTransactionOperation(state, action) {
		state.transactions = state.transactions.filter((transaction) => transaction.id !== action.input.id);
	},
	updateTransactionPeriodOperation(state, action) {
		const transaction = state.transactions.find((transaction) => transaction.id === action.input.id);
		if (!transaction) throw new Error(`Transaction with id ${action.input.id} not found`);
		transaction.accountingPeriod = action.input.accountingPeriod || "";
	}
};
//#endregion
//#region document-models/account-transactions/v1/src/reducers/budgets.ts
const accountTransactionsBudgetsOperations = {
	addBudgetOperation(state, action) {
		state.budgets.push({
			id: action.input.id,
			name: action.input.name || null
		});
	},
	updateBudgetOperation(state, action) {
		const budget = state.budgets.find((budget) => budget.id === action.input.id);
		if (!budget) throw new Error(`Budget with id ${action.input.id} not found`);
		if (action.input.name !== void 0 && action.input.name !== null) budget.name = action.input.name;
	},
	deleteBudgetOperation(state, action) {
		state.budgets = state.budgets.filter((budget) => budget.id !== action.input.id);
	}
};
//#endregion
//#region document-models/account-transactions/v1/gen/reducer.ts
const stateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	switch (action.type) {
		case "SET_ACCOUNT":
			SetAccountInputSchema().parse(action.input);
			accountTransactionsAccountOperations.setAccountOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_TRANSACTION":
			AddTransactionInputSchema().parse(action.input);
			accountTransactionsTransactionsOperations.addTransactionOperation(state[action.scope], action, dispatch);
			break;
		case "UPDATE_TRANSACTION":
			UpdateTransactionInputSchema().parse(action.input);
			accountTransactionsTransactionsOperations.updateTransactionOperation(state[action.scope], action, dispatch);
			break;
		case "DELETE_TRANSACTION":
			DeleteTransactionInputSchema().parse(action.input);
			accountTransactionsTransactionsOperations.deleteTransactionOperation(state[action.scope], action, dispatch);
			break;
		case "UPDATE_TRANSACTION_PERIOD":
			UpdateTransactionPeriodInputSchema().parse(action.input);
			accountTransactionsTransactionsOperations.updateTransactionPeriodOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_BUDGET":
			AddBudgetInputSchema().parse(action.input);
			accountTransactionsBudgetsOperations.addBudgetOperation(state[action.scope], action, dispatch);
			break;
		case "UPDATE_BUDGET":
			UpdateBudgetInputSchema().parse(action.input);
			accountTransactionsBudgetsOperations.updateBudgetOperation(state[action.scope], action, dispatch);
			break;
		case "DELETE_BUDGET":
			DeleteBudgetInputSchema().parse(action.input);
			accountTransactionsBudgetsOperations.deleteBudgetOperation(state[action.scope], action, dispatch);
			break;
		default: return state;
	}
};
const reducer = createReducer(stateReducer);
//#endregion
//#region document-models/account-transactions/v1/actions.ts
/** Actions for the AccountTransactions document model */
const actions = {
	...baseActions,
	...creators_exports,
	...creators_exports$1,
	...creators_exports$2
};
//#endregion
//#region document-models/account-transactions/v1/gen/document-type.ts
const accountTransactionsDocumentType = "powerhouse/account-transactions";
//#endregion
//#region document-models/account-transactions/v1/gen/document-schema.ts
/** Schema for validating the header object of a AccountTransactions document */
const AccountTransactionsDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal(accountTransactionsDocumentType) });
/** Schema for validating the state object of a AccountTransactions document */
const AccountTransactionsPHStateSchema = BaseDocumentStateSchema.extend({ global: AccountTransactionsStateSchema() });
const AccountTransactionsDocumentSchema = object({
	header: AccountTransactionsDocumentHeaderSchema,
	state: AccountTransactionsPHStateSchema,
	initialState: AccountTransactionsPHStateSchema
});
/** Simple helper function to check if a state object is a AccountTransactions document state object */
function isAccountTransactionsState(state) {
	return AccountTransactionsPHStateSchema.safeParse(state).success;
}
/** Simple helper function to assert that a document state object is a AccountTransactions document state object */
function assertIsAccountTransactionsState(state) {
	AccountTransactionsPHStateSchema.parse(state);
}
/** Simple helper function to check if a document is a AccountTransactions document */
function isAccountTransactionsDocument(document) {
	return AccountTransactionsDocumentSchema.safeParse(document).success;
}
/** Simple helper function to assert that a document is a AccountTransactions document */
function assertIsAccountTransactionsDocument(document) {
	AccountTransactionsDocumentSchema.parse(document);
}
//#endregion
//#region document-models/account-transactions/v1/gen/utils.ts
const initialGlobalState = {
	account: {
		id: "",
		account: "",
		name: "",
		budgetPath: null,
		accountTransactionsId: null,
		chain: null,
		type: null,
		owners: null,
		KycAmlStatus: null
	},
	transactions: [],
	budgets: []
};
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 = accountTransactionsDocumentType;
		document.header.id = generateId();
		return document;
	},
	saveToFileHandle(document, input) {
		return baseSaveToFileHandle(document, input);
	},
	loadFromInput(input) {
		return baseLoadFromInput(input, reducer);
	},
	isStateOfType(state) {
		return isAccountTransactionsState(state);
	},
	assertIsStateOfType(state) {
		return assertIsAccountTransactionsState(state);
	},
	isDocumentOfType(document) {
		return isAccountTransactionsDocument(document);
	},
	assertIsDocumentOfType(document) {
		return assertIsAccountTransactionsDocument(document);
	}
};
//#endregion
//#region document-models/account-transactions/v1/src/utils.ts
var utils_exports = /* @__PURE__ */ __exportAll({});
//#endregion
//#region document-models/account-transactions/v1/utils.ts
/** Utils for the AccountTransactions document model */
const utils = {
	...utils$1,
	...utils_exports
};
//#endregion
//#region document-models/account-transactions/v1/module.ts
/** Document model module for the AccountTransactions document type */
const AccountTransactions = {
	version: 1,
	reducer,
	actions,
	utils,
	documentModel: createState(defaultBaseState(), documentModel)
};
//#endregion
export { utils$1 as a, AccountTransactionsPHStateSchema as c, isAccountTransactionsDocument as d, isAccountTransactionsState as f, documentModel as g, reducer as h, initialLocalState as i, assertIsAccountTransactionsDocument as l, actions as m, utils as n, AccountTransactionsDocumentHeaderSchema as o, accountTransactionsDocumentType as p, initialGlobalState as r, AccountTransactionsDocumentSchema as s, AccountTransactions as t, assertIsAccountTransactionsState as u };

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