import { r as __exportAll } from "./chunk-BSw8zbkd.mjs";
import { A as any, B as url, F as literal, I as number, L as object, M as boolean, P as lazy, R as string, V as datetime, a as BaseDocumentHeaderSchema, b as generateId, c as baseCreateDocument, f as createAction, g as createState, h as createReducer, j as array, k as _enum, l as baseLoadFromInput, o as BaseDocumentStateSchema, s as baseActions, u as baseSaveToFileHandle, v as defaultBaseState, x as isDocumentAction } from "./dist-CYoGQ6PD.mjs";
//#region document-models/grant-application/v1/gen/document-model.ts
const documentModel = {
	id: "rfp-hub/grant-application",
	name: "GrantApplication",
	author: {
		name: "Powerhouse",
		website: "https://www.powerhouse.inc/"
	},
	extension: "rfpa",
	description: "DAOIP-5 GrantApplication — a project's submission to a grant pool. Richer reviewStage enum projects losslessly to DAOIP-5 6-value status.",
	specifications: [{
		state: {
			local: {
				schema: "",
				examples: [],
				initialValue: ""
			},
			global: {
				schema: "type GrantApplicationState {\n  # DAOIP-5 canonical GrantApplication\n  grantPoolsURI: URL\n  grantPoolId: PHID\n  grantPoolName: String\n  projectsURI: URL\n  projectId: PHID\n  projectName: String\n  createdAt: DateTime\n  contentURI: URL\n  discussionsTo: URL\n  licenseURI: URL\n  isInactive: Boolean!\n  applicationCompletionRate: Float\n  socials: [AppSocial!]!\n  fundsAsked: [AppFundingAmount!]!\n  fundsAskedInUSD: Amount_Fiat\n  fundsApproved: [AppFundingAmount!]!\n  fundsApprovedInUSD: Amount_Fiat\n  payoutAddress: PayoutAddress\n  status: ApplicationStatus!           # DAOIP-5 canonical 6-value enum\n  payouts: [Payout!]!\n  extensions: String\n\n  # Powerhouse additions\n  paymentTerm: PaymentTerm\n  reviewStage: ReviewStage!             # richer lifecycle (additive)\n  feedbackNotes: String\n  revisionCount: Int!\n  submitter: AppSubmitter\n  submittedAt: DateTime\n  reviewedBy: String\n  reviewedAt: DateTime\n}\n\nenum ApplicationStatus {\n  pending\n  in_review\n  approved\n  funded\n  rejected\n  completed\n}\n\nenum ReviewStage {\n  DRAFT\n  SUBMITTED\n  OPENED\n  UNDER_REVIEW\n  NEEDS_REVISION\n  REVISED\n  APPROVED\n  CONDITIONALLY_APPROVED\n  REJECTED\n  WITHDRAWN\n  FUNDED\n  COMPLETED\n}\n\nenum PaymentTerm {\n  MILESTONE_BASED_FIXED_PRICE\n  MILESTONE_BASED_ADVANCE_PAYMENT\n  RETAINER_BASED\n  VARIABLE_COST\n  ESCROW\n}\n\nenum AppSubmitterType {\n  COMMUNITY\n  VERIFIED_PUBLISHER\n  AUTOMATION\n}\n\ntype AppSubmitter {\n  submitterType: AppSubmitterType!\n  identifier: String!\n  submittedAt: DateTime!\n}\n\ntype AppSocial {\n  id: OID!\n  platform: String!\n  url: URL!\n}\n\ntype AppFundingAmount {\n  id: OID!\n  amount: Amount!\n}\n\ntype PayoutAddress {\n  addressType: String!\n  value: String!\n}\n\ntype Payout {\n  id: OID!\n  payoutType: String!\n  value: String!\n  proof: String\n  timestamp: DateTime!\n}\n",
				examples: [],
				initialValue: "{\"grantPoolsURI\": null, \"grantPoolId\": null, \"grantPoolName\": null, \"projectsURI\": null, \"projectId\": null, \"projectName\": null, \"createdAt\": null, \"contentURI\": null, \"discussionsTo\": null, \"licenseURI\": null, \"isInactive\": false, \"applicationCompletionRate\": null, \"socials\": [], \"fundsAsked\": [], \"fundsAskedInUSD\": null, \"fundsApproved\": [], \"fundsApprovedInUSD\": null, \"payoutAddress\": null, \"status\": \"pending\", \"payouts\": [], \"extensions\": null, \"paymentTerm\": null, \"reviewStage\": \"DRAFT\", \"feedbackNotes\": null, \"revisionCount\": 0, \"submitter\": null, \"submittedAt\": null, \"reviewedBy\": null, \"reviewedAt\": null}"
			}
		},
		modules: [
			{
				id: "metadata-module",
				name: "metadata",
				description: "Pool+project refs, content links, socials",
				operations: [
					{
						id: "ga-set-pool-ref",
						name: "SET_POOL_REF",
						description: "",
						schema: "input SetPoolRefInput {\n    grantPoolsURI: URL!\n    grantPoolId: PHID!\n    grantPoolName: String!\n}",
						template: "",
						reducer: "state.grantPoolsURI = action.input.grantPoolsURI;\nstate.grantPoolId = action.input.grantPoolId;\nstate.grantPoolName = action.input.grantPoolName;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-project-ref",
						name: "SET_PROJECT_REF",
						description: "",
						schema: "input SetProjectRefInput {\n    projectsURI: URL!\n    projectId: PHID!\n    projectName: String!\n}",
						template: "",
						reducer: "state.projectsURI = action.input.projectsURI;\nstate.projectId = action.input.projectId;\nstate.projectName = action.input.projectName;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-created-at",
						name: "SET_CREATED_AT",
						description: "",
						schema: "input SetCreatedAtInput {\n    createdAt: DateTime!\n}",
						template: "",
						reducer: "state.createdAt = action.input.createdAt;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-app-content-uri",
						name: "SET_APP_CONTENT_URI",
						description: "",
						schema: "input SetAppContentUriInput {\n    contentURI: URL\n}",
						template: "",
						reducer: "state.contentURI = action.input.contentURI || null;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-discussions-to",
						name: "SET_DISCUSSIONS_TO",
						description: "",
						schema: "input SetDiscussionsToInput {\n    discussionsTo: URL\n}",
						template: "",
						reducer: "state.discussionsTo = action.input.discussionsTo || null;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-app-license-uri",
						name: "SET_APP_LICENSE_URI",
						description: "",
						schema: "input SetAppLicenseUriInput {\n    licenseURI: URL\n}",
						template: "",
						reducer: "state.licenseURI = action.input.licenseURI || null;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-is-inactive",
						name: "SET_IS_INACTIVE",
						description: "",
						schema: "input SetIsInactiveInput {\n    isInactive: Boolean!\n}",
						template: "",
						reducer: "state.isInactive = action.input.isInactive;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-completion-rate",
						name: "SET_COMPLETION_RATE",
						description: "",
						schema: "input SetCompletionRateInput {\n    applicationCompletionRate: Float\n}",
						template: "",
						reducer: "state.applicationCompletionRate = action.input.applicationCompletionRate || null;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-app-extensions",
						name: "SET_APP_EXTENSIONS",
						description: "",
						schema: "input SetAppExtensionsInput {\n    extensions: String\n}",
						template: "",
						reducer: "state.extensions = action.input.extensions || null;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-add-app-social",
						name: "ADD_APP_SOCIAL",
						description: "",
						schema: "input AddAppSocialInput {\n    id: OID!\n    platform: String!\n    url: URL!\n}",
						template: "",
						reducer: "state.socials.push({id: action.input.id, platform: action.input.platform, url: action.input.url});",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-remove-app-social",
						name: "REMOVE_APP_SOCIAL",
						description: "",
						schema: "input RemoveAppSocialInput {\n    id: OID!\n}",
						template: "",
						reducer: "const idx = state.socials.findIndex((s) => s.id === action.input.id);\nif (idx === -1) throw new AppSocialNotFoundError(`Social ${action.input.id} not found`);\nstate.socials.splice(idx, 1);",
						errors: [{
							id: "err-ga-social-not-found",
							name: "AppSocialNotFoundError",
							code: "APP_SOCIAL_NOT_FOUND",
							description: "Social entry not found.",
							template: ""
						}],
						examples: [],
						scope: "global"
					}
				]
			},
			{
				id: "funding-module",
				name: "funding",
				description: "Funds asked, funds approved, payout address, payment term",
				operations: [
					{
						id: "ga-add-funds-asked",
						name: "ADD_FUNDS_ASKED",
						description: "",
						schema: "input AddFundsAskedInput {\n    id: OID!\n    amount: Amount!\n}",
						template: "",
						reducer: "state.fundsAsked.push({id: action.input.id, amount: action.input.amount});",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-remove-funds-asked",
						name: "REMOVE_FUNDS_ASKED",
						description: "",
						schema: "input RemoveFundsAskedInput {\n    id: OID!\n}",
						template: "",
						reducer: "const idx = state.fundsAsked.findIndex((f) => f.id === action.input.id);\nif (idx === -1) throw new FundsAskedNotFoundError(`Funds-asked entry ${action.input.id} not found`);\nstate.fundsAsked.splice(idx, 1);",
						errors: [{
							id: "err-ga-funds-asked-not-found",
							name: "FundsAskedNotFoundError",
							code: "FUNDS_ASKED_NOT_FOUND",
							description: "Funds-asked entry not found.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-funds-asked-usd",
						name: "SET_FUNDS_ASKED_USD",
						description: "",
						schema: "input SetFundsAskedUsdInput {\n    fundsAskedInUSD: Amount_Fiat\n}",
						template: "",
						reducer: "state.fundsAskedInUSD = action.input.fundsAskedInUSD || null;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-add-funds-approved",
						name: "ADD_FUNDS_APPROVED",
						description: "",
						schema: "input AddFundsApprovedInput {\n    id: OID!\n    amount: Amount!\n}",
						template: "",
						reducer: "state.fundsApproved.push({id: action.input.id, amount: action.input.amount});",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-funds-approved-usd",
						name: "SET_FUNDS_APPROVED_USD",
						description: "",
						schema: "input SetFundsApprovedUsdInput {\n    fundsApprovedInUSD: Amount_Fiat\n}",
						template: "",
						reducer: "state.fundsApprovedInUSD = action.input.fundsApprovedInUSD || null;",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-payout-address",
						name: "SET_PAYOUT_ADDRESS",
						description: "",
						schema: "input SetPayoutAddressInput {\n    addressType: String!\n    value: String!\n}",
						template: "",
						reducer: "state.payoutAddress = {\n  addressType: action.input.addressType,\n  value: action.input.value,\n};",
						errors: [],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-set-payment-term",
						name: "SET_PAYMENT_TERM",
						description: "",
						schema: "input SetPaymentTermInput {\n    paymentTerm: PaymentTerm!\n}",
						template: "",
						reducer: "state.paymentTerm = action.input.paymentTerm;",
						errors: [],
						examples: [],
						scope: "global"
					}
				]
			},
			{
				id: "review-module",
				name: "review",
				description: "Submission + review lifecycle (reviewStage + DAOIP-5 status)",
				operations: [
					{
						id: "ga-submit-application",
						name: "SUBMIT_APPLICATION",
						description: "",
						schema: "input SubmitApplicationInput {\n    submittedAt: DateTime!\n    submitterType: AppSubmitterType!\n    identifier: String!\n}",
						template: "",
						reducer: "const legal = [\"DRAFT\", \"REVISED\", \"NEEDS_REVISION\"];\nif (!legal.includes(state.reviewStage)) {\n  throw new InvalidSubmitTransitionError(\n    `Cannot transition from ${state.reviewStage} to SUBMITTED`\n  );\n}\nstate.reviewStage = \"SUBMITTED\";\nstate.status = \"pending\";\nstate.submittedAt = action.input.submittedAt;\nstate.submitter = {\n  submitterType: action.input.submitterType,\n  identifier: action.input.identifier,\n  submittedAt: action.input.submittedAt,\n};",
						errors: [{
							id: "err-ga-invalid-submit",
							name: "InvalidSubmitTransitionError",
							code: "INVALID_SUBMIT_TRANSITION",
							description: "Invalid reviewStage transition.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-open-application",
						name: "OPEN_APPLICATION",
						description: "",
						schema: "input OpenApplicationInput {\n    openedAt: DateTime!\n}",
						template: "",
						reducer: "const legal = [\"SUBMITTED\"];\nif (!legal.includes(state.reviewStage)) {\n  throw new InvalidOpenTransitionError(\n    `Cannot transition from ${state.reviewStage} to OPENED`\n  );\n}\nstate.reviewStage = \"OPENED\";\nstate.status = \"pending\";\n",
						errors: [{
							id: "err-ga-invalid-open",
							name: "InvalidOpenTransitionError",
							code: "INVALID_OPEN_TRANSITION",
							description: "Cannot open from current reviewStage.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-start-review",
						name: "START_REVIEW",
						description: "",
						schema: "input StartReviewInput {\n    reviewerDid: String!\n    startedAt: DateTime!\n}",
						template: "",
						reducer: "const legal = [\"SUBMITTED\", \"OPENED\"];\nif (!legal.includes(state.reviewStage)) {\n  throw new InvalidStartReviewError(\n    `Cannot transition from ${state.reviewStage} to UNDER_REVIEW`\n  );\n}\nstate.reviewStage = \"UNDER_REVIEW\";\nstate.status = \"in_review\";\nstate.reviewedBy = action.input.reviewerDid;",
						errors: [{
							id: "err-ga-invalid-start-review",
							name: "InvalidStartReviewError",
							code: "INVALID_START_REVIEW",
							description: "Cannot start review from current reviewStage.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-request-revision",
						name: "REQUEST_REVISION",
						description: "",
						schema: "input RequestRevisionInput {\n    feedbackNotes: String!\n    requestedAt: DateTime!\n}",
						template: "",
						reducer: "const legal = [\"UNDER_REVIEW\"];\nif (!legal.includes(state.reviewStage)) {\n  throw new InvalidRequestRevisionError(\n    `Cannot transition from ${state.reviewStage} to NEEDS_REVISION`\n  );\n}\nstate.reviewStage = \"NEEDS_REVISION\";\nstate.status = \"in_review\";\nstate.feedbackNotes = action.input.feedbackNotes;",
						errors: [{
							id: "err-ga-invalid-request-revision",
							name: "InvalidRequestRevisionError",
							code: "INVALID_REQUEST_REVISION",
							description: "Cannot request revision from current reviewStage.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-mark-revised",
						name: "MARK_REVISED",
						description: "",
						schema: "input MarkRevisedInput {\n    revisedAt: DateTime!\n}",
						template: "",
						reducer: "if (state.reviewStage !== \"NEEDS_REVISION\") {\n  throw new InvalidMarkRevisedError(`Can only mark revised from NEEDS_REVISION`);\n}\nstate.reviewStage = \"REVISED\";\nstate.status = \"in_review\";\nstate.revisionCount += 1;",
						errors: [{
							id: "err-ga-invalid-mark-revised",
							name: "InvalidMarkRevisedError",
							code: "INVALID_MARK_REVISED",
							description: "Cannot mark revised unless NEEDS_REVISION.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-approve-application",
						name: "APPROVE_APPLICATION",
						description: "",
						schema: "input ApproveApplicationInput {\n    approvedAt: DateTime!\n    reviewerDid: String!\n}",
						template: "",
						reducer: "const legal = [\"UNDER_REVIEW\", \"REVISED\"];\nif (!legal.includes(state.reviewStage)) {\n  throw new InvalidApproveError(\n    `Cannot transition from ${state.reviewStage} to APPROVED`\n  );\n}\nstate.reviewStage = \"APPROVED\";\nstate.status = \"approved\";\nstate.reviewedBy = action.input.reviewerDid;\nstate.reviewedAt = action.input.approvedAt;",
						errors: [{
							id: "err-ga-invalid-approve",
							name: "InvalidApproveError",
							code: "INVALID_APPROVE",
							description: "Cannot approve from current reviewStage.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-conditionally-approve",
						name: "CONDITIONALLY_APPROVE",
						description: "",
						schema: "input ConditionallyApproveInput {\n    approvedAt: DateTime!\n    conditions: String!\n    reviewerDid: String!\n}",
						template: "",
						reducer: "const legal = [\"UNDER_REVIEW\", \"REVISED\"];\nif (!legal.includes(state.reviewStage)) {\n  throw new InvalidConditionalApproveError(\n    `Cannot transition from ${state.reviewStage} to CONDITIONALLY_APPROVED`\n  );\n}\nstate.reviewStage = \"CONDITIONALLY_APPROVED\";\nstate.status = \"approved\";\nstate.reviewedBy = action.input.reviewerDid;\nstate.reviewedAt = action.input.approvedAt;\nstate.feedbackNotes = action.input.conditions;",
						errors: [{
							id: "err-ga-invalid-conditional",
							name: "InvalidConditionalApproveError",
							code: "INVALID_CONDITIONAL_APPROVE",
							description: "Cannot conditionally approve from current reviewStage.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-reject-application",
						name: "REJECT_APPLICATION",
						description: "",
						schema: "input RejectApplicationInput {\n    rejectedAt: DateTime!\n    reason: String!\n    reviewerDid: String!\n}",
						template: "",
						reducer: "const legal = [\"UNDER_REVIEW\", \"REVISED\"];\nif (!legal.includes(state.reviewStage)) {\n  throw new InvalidRejectError(\n    `Cannot transition from ${state.reviewStage} to REJECTED`\n  );\n}\nstate.reviewStage = \"REJECTED\";\nstate.status = \"rejected\";\nstate.reviewedBy = action.input.reviewerDid;\nstate.reviewedAt = action.input.rejectedAt;\nstate.feedbackNotes = action.input.reason;",
						errors: [{
							id: "err-ga-invalid-reject",
							name: "InvalidRejectError",
							code: "INVALID_REJECT",
							description: "Cannot reject from current reviewStage.",
							template: ""
						}],
						examples: [],
						scope: "global"
					},
					{
						id: "ga-withdraw-application",
						name: "WITHDRAW_APPLICATION",
						description: "",
						schema: "input WithdrawApplicationInput {\n    withdrawnAt: DateTime!\n    reason: String\n}",
						template: "",
						reducer: "if ([\"DRAFT\", \"SUBMITTED\", \"OPENED\", \"UNDER_REVIEW\", \"NEEDS_REVISION\", \"REVISED\"].indexOf(state.reviewStage) === -1) {\n  throw new InvalidWithdrawError(`Cannot withdraw from ${state.reviewStage}`);\n}\nstate.reviewStage = \"WITHDRAWN\";\nstate.status = \"rejected\";",
						errors: [{
							id: "err-ga-invalid-withdraw",
							name: "InvalidWithdrawError",
							code: "INVALID_WITHDRAW",
							description: "Cannot withdraw from current reviewStage.",
							template: ""
						}],
						examples: [],
						scope: "global"
					}
				]
			},
			{
				id: "payouts-module",
				name: "payouts",
				description: "Payout records + completion marking",
				operations: [{
					id: "ga-record-payout",
					name: "RECORD_PAYOUT",
					description: "",
					schema: "input RecordPayoutInput {\n    id: OID!\n    payoutType: String!\n    value: String!\n    proof: String\n    timestamp: DateTime!\n}",
					template: "",
					reducer: "state.payouts.push({\n  id: action.input.id,\n  payoutType: action.input.payoutType,\n  value: action.input.value,\n  proof: action.input.proof || null,\n  timestamp: action.input.timestamp,\n});\nstate.reviewStage = \"FUNDED\";\nstate.status = \"funded\";",
					errors: [],
					examples: [],
					scope: "global"
				}, {
					id: "ga-mark-completed",
					name: "MARK_COMPLETED",
					description: "",
					schema: "input MarkCompletedInput {\n    completedAt: DateTime!\n}",
					template: "",
					reducer: "if (state.reviewStage !== \"FUNDED\") {\n  throw new InvalidCompleteError(`Can only mark completed after FUNDED`);\n}\nstate.reviewStage = \"COMPLETED\";\nstate.status = \"completed\";",
					errors: [{
						id: "err-ga-invalid-complete",
						name: "InvalidCompleteError",
						code: "INVALID_COMPLETE",
						description: "Cannot mark completed unless FUNDED.",
						template: ""
					}],
					examples: [],
					scope: "global"
				}]
			}
		],
		version: 1,
		changeLog: []
	}]
};
//#endregion
//#region document-models/grant-application/v1/gen/metadata/error.ts
var AppSocialNotFoundError = class extends Error {
	errorCode = "AppSocialNotFoundError";
	constructor(message = "AppSocialNotFoundError") {
		super(message);
	}
};
//#endregion
//#region document-models/grant-application/v1/src/reducers/metadata.ts
const grantApplicationMetadataOperations = {
	setPoolRefOperation(state, action) {
		state.grantPoolsURI = action.input.grantPoolsURI;
		state.grantPoolId = action.input.grantPoolId;
		state.grantPoolName = action.input.grantPoolName;
	},
	setProjectRefOperation(state, action) {
		state.projectsURI = action.input.projectsURI;
		state.projectId = action.input.projectId;
		state.projectName = action.input.projectName;
	},
	setCreatedAtOperation(state, action) {
		state.createdAt = action.input.createdAt;
	},
	setAppContentUriOperation(state, action) {
		state.contentURI = action.input.contentURI || null;
	},
	setDiscussionsToOperation(state, action) {
		state.discussionsTo = action.input.discussionsTo || null;
	},
	setAppLicenseUriOperation(state, action) {
		state.licenseURI = action.input.licenseURI || null;
	},
	setIsInactiveOperation(state, action) {
		state.isInactive = action.input.isInactive;
	},
	setCompletionRateOperation(state, action) {
		state.applicationCompletionRate = action.input.applicationCompletionRate || null;
	},
	setAppExtensionsOperation(state, action) {
		state.extensions = action.input.extensions || null;
	},
	addAppSocialOperation(state, action) {
		state.socials.push({
			id: action.input.id,
			platform: action.input.platform,
			url: action.input.url
		});
	},
	removeAppSocialOperation(state, action) {
		const idx = state.socials.findIndex((s) => s.id === action.input.id);
		if (idx === -1) throw new AppSocialNotFoundError(`Social ${action.input.id} not found`);
		state.socials.splice(idx, 1);
	}
};
//#endregion
//#region document-models/grant-application/v1/gen/funding/error.ts
var FundsAskedNotFoundError = class extends Error {
	errorCode = "FundsAskedNotFoundError";
	constructor(message = "FundsAskedNotFoundError") {
		super(message);
	}
};
//#endregion
//#region document-models/grant-application/v1/src/reducers/funding.ts
const grantApplicationFundingOperations = {
	addFundsAskedOperation(state, action) {
		state.fundsAsked.push({
			id: action.input.id,
			amount: action.input.amount
		});
	},
	removeFundsAskedOperation(state, action) {
		const idx = state.fundsAsked.findIndex((f) => f.id === action.input.id);
		if (idx === -1) throw new FundsAskedNotFoundError(`Funds-asked entry ${action.input.id} not found`);
		state.fundsAsked.splice(idx, 1);
	},
	setFundsAskedUsdOperation(state, action) {
		state.fundsAskedInUSD = action.input.fundsAskedInUSD || null;
	},
	addFundsApprovedOperation(state, action) {
		state.fundsApproved.push({
			id: action.input.id,
			amount: action.input.amount
		});
	},
	setFundsApprovedUsdOperation(state, action) {
		state.fundsApprovedInUSD = action.input.fundsApprovedInUSD || null;
	},
	setPayoutAddressOperation(state, action) {
		state.payoutAddress = {
			addressType: action.input.addressType,
			value: action.input.value
		};
	},
	setPaymentTermOperation(state, action) {
		state.paymentTerm = action.input.paymentTerm;
	}
};
//#endregion
//#region document-models/grant-application/v1/src/reducers/review.ts
const grantApplicationReviewOperations = {
	submitApplicationOperation(state, action) {
		if (![
			"DRAFT",
			"REVISED",
			"NEEDS_REVISION"
		].includes(state.reviewStage)) throw new Error(`Cannot submit from ${state.reviewStage}`);
		state.reviewStage = "SUBMITTED";
		state.status = "pending";
		state.submittedAt = action.input.submittedAt;
		state.submitter = {
			submitterType: action.input.submitterType,
			identifier: action.input.identifier,
			submittedAt: action.input.submittedAt
		};
	},
	openApplicationOperation(state, _action) {
		if (state.reviewStage !== "SUBMITTED") throw new Error(`Cannot open from ${state.reviewStage}`);
		state.reviewStage = "OPENED";
		state.status = "pending";
	},
	startReviewOperation(state, action) {
		if (!["SUBMITTED", "OPENED"].includes(state.reviewStage)) throw new Error(`Cannot start review from ${state.reviewStage}`);
		state.reviewStage = "UNDER_REVIEW";
		state.status = "in_review";
		state.reviewedBy = action.input.reviewerDid;
	},
	requestRevisionOperation(state, action) {
		if (state.reviewStage !== "UNDER_REVIEW") throw new Error(`Cannot request revision from ${state.reviewStage}`);
		state.reviewStage = "NEEDS_REVISION";
		state.status = "in_review";
		state.feedbackNotes = action.input.feedbackNotes;
	},
	markRevisedOperation(state, _action) {
		if (state.reviewStage !== "NEEDS_REVISION") throw new Error(`Can only mark revised from NEEDS_REVISION`);
		state.reviewStage = "REVISED";
		state.status = "in_review";
		state.revisionCount += 1;
	},
	approveApplicationOperation(state, action) {
		if (!["UNDER_REVIEW", "REVISED"].includes(state.reviewStage)) throw new Error(`Cannot approve from ${state.reviewStage}`);
		state.reviewStage = "APPROVED";
		state.status = "approved";
		state.reviewedBy = action.input.reviewerDid;
		state.reviewedAt = action.input.approvedAt;
	},
	conditionallyApproveOperation(state, action) {
		if (!["UNDER_REVIEW", "REVISED"].includes(state.reviewStage)) throw new Error(`Cannot conditionally approve from ${state.reviewStage}`);
		state.reviewStage = "CONDITIONALLY_APPROVED";
		state.status = "approved";
		state.reviewedBy = action.input.reviewerDid;
		state.reviewedAt = action.input.approvedAt;
		state.feedbackNotes = action.input.conditions;
	},
	rejectApplicationOperation(state, action) {
		if (!["UNDER_REVIEW", "REVISED"].includes(state.reviewStage)) throw new Error(`Cannot reject from ${state.reviewStage}`);
		state.reviewStage = "REJECTED";
		state.status = "rejected";
		state.reviewedBy = action.input.reviewerDid;
		state.reviewedAt = action.input.rejectedAt;
		state.feedbackNotes = action.input.reason;
	},
	withdrawApplicationOperation(state, _action) {
		if (![
			"DRAFT",
			"SUBMITTED",
			"OPENED",
			"UNDER_REVIEW",
			"NEEDS_REVISION",
			"REVISED"
		].includes(state.reviewStage)) throw new Error(`Cannot withdraw from ${state.reviewStage}`);
		state.reviewStage = "WITHDRAWN";
		state.status = "rejected";
	}
};
//#endregion
//#region document-models/grant-application/v1/src/reducers/payouts.ts
const grantApplicationPayoutsOperations = {
	recordPayoutOperation(state, action) {
		state.payouts.push({
			id: action.input.id,
			payoutType: action.input.payoutType,
			value: action.input.value,
			proof: action.input.proof || null,
			timestamp: action.input.timestamp
		});
		state.reviewStage = "FUNDED";
		state.status = "funded";
	},
	markCompletedOperation(state, _action) {
		if (state.reviewStage !== "FUNDED") throw new Error(`Can only mark completed after FUNDED`);
		state.reviewStage = "COMPLETED";
		state.status = "completed";
	}
};
//#endregion
//#region document-models/grant-application/v1/gen/schema/zod.ts
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
const definedNonNullAnySchema = any().refine((v) => isDefinedNonNullAny(v));
const AppSubmitterTypeSchema = _enum([
	"AUTOMATION",
	"COMMUNITY",
	"VERIFIED_PUBLISHER"
]);
const ApplicationStatusSchema = _enum([
	"approved",
	"completed",
	"funded",
	"in_review",
	"pending",
	"rejected"
]);
const PaymentTermSchema = _enum([
	"ESCROW",
	"MILESTONE_BASED_ADVANCE_PAYMENT",
	"MILESTONE_BASED_FIXED_PRICE",
	"RETAINER_BASED",
	"VARIABLE_COST"
]);
const ReviewStageSchema = _enum([
	"APPROVED",
	"COMPLETED",
	"CONDITIONALLY_APPROVED",
	"DRAFT",
	"FUNDED",
	"NEEDS_REVISION",
	"OPENED",
	"REJECTED",
	"REVISED",
	"SUBMITTED",
	"UNDER_REVIEW",
	"WITHDRAWN"
]);
function AddAppSocialInputSchema() {
	return object({
		id: string(),
		platform: string(),
		url: url()
	});
}
function AddFundsApprovedInputSchema() {
	return object({
		amount: object({
			unit: string().optional(),
			value: number().finite()
		}),
		id: string()
	});
}
function AddFundsAskedInputSchema() {
	return object({
		amount: object({
			unit: string().optional(),
			value: number().finite()
		}),
		id: string()
	});
}
function AppFundingAmountSchema() {
	return object({
		__typename: literal("AppFundingAmount").optional(),
		amount: object({
			unit: string().optional(),
			value: number().finite()
		}),
		id: string()
	});
}
function AppSocialSchema() {
	return object({
		__typename: literal("AppSocial").optional(),
		id: string(),
		platform: string(),
		url: url()
	});
}
function AppSubmitterSchema() {
	return object({
		__typename: literal("AppSubmitter").optional(),
		identifier: string(),
		submittedAt: datetime(),
		submitterType: AppSubmitterTypeSchema
	});
}
function ApproveApplicationInputSchema() {
	return object({
		approvedAt: datetime(),
		reviewerDid: string()
	});
}
function ConditionallyApproveInputSchema() {
	return object({
		approvedAt: datetime(),
		conditions: string(),
		reviewerDid: string()
	});
}
function GrantApplicationStateSchema() {
	return object({
		__typename: literal("GrantApplicationState").optional(),
		applicationCompletionRate: number().nullish(),
		contentURI: url().nullish(),
		createdAt: datetime().nullish(),
		discussionsTo: url().nullish(),
		extensions: string().nullish(),
		feedbackNotes: string().nullish(),
		fundsApproved: array(lazy(() => AppFundingAmountSchema())),
		fundsApprovedInUSD: object({
			unit: string(),
			value: number().finite()
		}).nullish(),
		fundsAsked: array(lazy(() => AppFundingAmountSchema())),
		fundsAskedInUSD: object({
			unit: string(),
			value: number().finite()
		}).nullish(),
		grantPoolId: string().nullish(),
		grantPoolName: string().nullish(),
		grantPoolsURI: url().nullish(),
		isInactive: boolean(),
		licenseURI: url().nullish(),
		paymentTerm: PaymentTermSchema.nullish(),
		payoutAddress: lazy(() => PayoutAddressSchema().nullish()),
		payouts: array(lazy(() => PayoutSchema())),
		projectId: string().nullish(),
		projectName: string().nullish(),
		projectsURI: url().nullish(),
		reviewStage: ReviewStageSchema,
		reviewedAt: datetime().nullish(),
		reviewedBy: string().nullish(),
		revisionCount: number(),
		socials: array(lazy(() => AppSocialSchema())),
		status: ApplicationStatusSchema,
		submittedAt: datetime().nullish(),
		submitter: lazy(() => AppSubmitterSchema().nullish())
	});
}
function MarkCompletedInputSchema() {
	return object({ completedAt: datetime() });
}
function MarkRevisedInputSchema() {
	return object({ revisedAt: datetime() });
}
function OpenApplicationInputSchema() {
	return object({ openedAt: datetime() });
}
function PayoutSchema() {
	return object({
		__typename: literal("Payout").optional(),
		id: string(),
		payoutType: string(),
		proof: string().nullish(),
		timestamp: datetime(),
		value: string()
	});
}
function PayoutAddressSchema() {
	return object({
		__typename: literal("PayoutAddress").optional(),
		addressType: string(),
		value: string()
	});
}
function RecordPayoutInputSchema() {
	return object({
		id: string(),
		payoutType: string(),
		proof: string().nullish(),
		timestamp: datetime(),
		value: string()
	});
}
function RejectApplicationInputSchema() {
	return object({
		reason: string(),
		rejectedAt: datetime(),
		reviewerDid: string()
	});
}
function RemoveAppSocialInputSchema() {
	return object({ id: string() });
}
function RemoveFundsAskedInputSchema() {
	return object({ id: string() });
}
function RequestRevisionInputSchema() {
	return object({
		feedbackNotes: string(),
		requestedAt: datetime()
	});
}
function SetAppContentUriInputSchema() {
	return object({ contentURI: url().nullish() });
}
function SetAppExtensionsInputSchema() {
	return object({ extensions: string().nullish() });
}
function SetAppLicenseUriInputSchema() {
	return object({ licenseURI: url().nullish() });
}
function SetCompletionRateInputSchema() {
	return object({ applicationCompletionRate: number().nullish() });
}
function SetCreatedAtInputSchema() {
	return object({ createdAt: datetime() });
}
function SetDiscussionsToInputSchema() {
	return object({ discussionsTo: url().nullish() });
}
function SetFundsApprovedUsdInputSchema() {
	return object({ fundsApprovedInUSD: object({
		unit: string(),
		value: number().finite()
	}).nullish() });
}
function SetFundsAskedUsdInputSchema() {
	return object({ fundsAskedInUSD: object({
		unit: string(),
		value: number().finite()
	}).nullish() });
}
function SetIsInactiveInputSchema() {
	return object({ isInactive: boolean() });
}
function SetPaymentTermInputSchema() {
	return object({ paymentTerm: PaymentTermSchema });
}
function SetPayoutAddressInputSchema() {
	return object({
		addressType: string(),
		value: string()
	});
}
function SetPoolRefInputSchema() {
	return object({
		grantPoolId: string(),
		grantPoolName: string(),
		grantPoolsURI: url()
	});
}
function SetProjectRefInputSchema() {
	return object({
		projectId: string(),
		projectName: string(),
		projectsURI: url()
	});
}
function StartReviewInputSchema() {
	return object({
		reviewerDid: string(),
		startedAt: datetime()
	});
}
function SubmitApplicationInputSchema() {
	return object({
		identifier: string(),
		submittedAt: datetime(),
		submitterType: AppSubmitterTypeSchema
	});
}
function WithdrawApplicationInputSchema() {
	return object({
		reason: string().nullish(),
		withdrawnAt: datetime()
	});
}
//#endregion
//#region document-models/grant-application/v1/gen/reducer.ts
const stateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	switch (action.type) {
		case "SET_POOL_REF":
			SetPoolRefInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setPoolRefOperation(state[action.scope], action, dispatch);
			break;
		case "SET_PROJECT_REF":
			SetProjectRefInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setProjectRefOperation(state[action.scope], action, dispatch);
			break;
		case "SET_CREATED_AT":
			SetCreatedAtInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setCreatedAtOperation(state[action.scope], action, dispatch);
			break;
		case "SET_APP_CONTENT_URI":
			SetAppContentUriInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setAppContentUriOperation(state[action.scope], action, dispatch);
			break;
		case "SET_DISCUSSIONS_TO":
			SetDiscussionsToInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setDiscussionsToOperation(state[action.scope], action, dispatch);
			break;
		case "SET_APP_LICENSE_URI":
			SetAppLicenseUriInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setAppLicenseUriOperation(state[action.scope], action, dispatch);
			break;
		case "SET_IS_INACTIVE":
			SetIsInactiveInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setIsInactiveOperation(state[action.scope], action, dispatch);
			break;
		case "SET_COMPLETION_RATE":
			SetCompletionRateInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setCompletionRateOperation(state[action.scope], action, dispatch);
			break;
		case "SET_APP_EXTENSIONS":
			SetAppExtensionsInputSchema().parse(action.input);
			grantApplicationMetadataOperations.setAppExtensionsOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_APP_SOCIAL":
			AddAppSocialInputSchema().parse(action.input);
			grantApplicationMetadataOperations.addAppSocialOperation(state[action.scope], action, dispatch);
			break;
		case "REMOVE_APP_SOCIAL":
			RemoveAppSocialInputSchema().parse(action.input);
			grantApplicationMetadataOperations.removeAppSocialOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_FUNDS_ASKED":
			AddFundsAskedInputSchema().parse(action.input);
			grantApplicationFundingOperations.addFundsAskedOperation(state[action.scope], action, dispatch);
			break;
		case "REMOVE_FUNDS_ASKED":
			RemoveFundsAskedInputSchema().parse(action.input);
			grantApplicationFundingOperations.removeFundsAskedOperation(state[action.scope], action, dispatch);
			break;
		case "SET_FUNDS_ASKED_USD":
			SetFundsAskedUsdInputSchema().parse(action.input);
			grantApplicationFundingOperations.setFundsAskedUsdOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_FUNDS_APPROVED":
			AddFundsApprovedInputSchema().parse(action.input);
			grantApplicationFundingOperations.addFundsApprovedOperation(state[action.scope], action, dispatch);
			break;
		case "SET_FUNDS_APPROVED_USD":
			SetFundsApprovedUsdInputSchema().parse(action.input);
			grantApplicationFundingOperations.setFundsApprovedUsdOperation(state[action.scope], action, dispatch);
			break;
		case "SET_PAYOUT_ADDRESS":
			SetPayoutAddressInputSchema().parse(action.input);
			grantApplicationFundingOperations.setPayoutAddressOperation(state[action.scope], action, dispatch);
			break;
		case "SET_PAYMENT_TERM":
			SetPaymentTermInputSchema().parse(action.input);
			grantApplicationFundingOperations.setPaymentTermOperation(state[action.scope], action, dispatch);
			break;
		case "SUBMIT_APPLICATION":
			SubmitApplicationInputSchema().parse(action.input);
			grantApplicationReviewOperations.submitApplicationOperation(state[action.scope], action, dispatch);
			break;
		case "OPEN_APPLICATION":
			OpenApplicationInputSchema().parse(action.input);
			grantApplicationReviewOperations.openApplicationOperation(state[action.scope], action, dispatch);
			break;
		case "START_REVIEW":
			StartReviewInputSchema().parse(action.input);
			grantApplicationReviewOperations.startReviewOperation(state[action.scope], action, dispatch);
			break;
		case "REQUEST_REVISION":
			RequestRevisionInputSchema().parse(action.input);
			grantApplicationReviewOperations.requestRevisionOperation(state[action.scope], action, dispatch);
			break;
		case "MARK_REVISED":
			MarkRevisedInputSchema().parse(action.input);
			grantApplicationReviewOperations.markRevisedOperation(state[action.scope], action, dispatch);
			break;
		case "APPROVE_APPLICATION":
			ApproveApplicationInputSchema().parse(action.input);
			grantApplicationReviewOperations.approveApplicationOperation(state[action.scope], action, dispatch);
			break;
		case "CONDITIONALLY_APPROVE":
			ConditionallyApproveInputSchema().parse(action.input);
			grantApplicationReviewOperations.conditionallyApproveOperation(state[action.scope], action, dispatch);
			break;
		case "REJECT_APPLICATION":
			RejectApplicationInputSchema().parse(action.input);
			grantApplicationReviewOperations.rejectApplicationOperation(state[action.scope], action, dispatch);
			break;
		case "WITHDRAW_APPLICATION":
			WithdrawApplicationInputSchema().parse(action.input);
			grantApplicationReviewOperations.withdrawApplicationOperation(state[action.scope], action, dispatch);
			break;
		case "RECORD_PAYOUT":
			RecordPayoutInputSchema().parse(action.input);
			grantApplicationPayoutsOperations.recordPayoutOperation(state[action.scope], action, dispatch);
			break;
		case "MARK_COMPLETED":
			MarkCompletedInputSchema().parse(action.input);
			grantApplicationPayoutsOperations.markCompletedOperation(state[action.scope], action, dispatch);
			break;
		default: return state;
	}
};
const reducer = createReducer(stateReducer);
//#endregion
//#region document-models/grant-application/v1/gen/metadata/creators.ts
var creators_exports$3 = /* @__PURE__ */ __exportAll({
	addAppSocial: () => addAppSocial,
	removeAppSocial: () => removeAppSocial,
	setAppContentUri: () => setAppContentUri,
	setAppExtensions: () => setAppExtensions,
	setAppLicenseUri: () => setAppLicenseUri,
	setCompletionRate: () => setCompletionRate,
	setCreatedAt: () => setCreatedAt,
	setDiscussionsTo: () => setDiscussionsTo,
	setIsInactive: () => setIsInactive,
	setPoolRef: () => setPoolRef,
	setProjectRef: () => setProjectRef
});
const setPoolRef = (input) => createAction("SET_POOL_REF", { ...input }, void 0, SetPoolRefInputSchema, "global");
const setProjectRef = (input) => createAction("SET_PROJECT_REF", { ...input }, void 0, SetProjectRefInputSchema, "global");
const setCreatedAt = (input) => createAction("SET_CREATED_AT", { ...input }, void 0, SetCreatedAtInputSchema, "global");
const setAppContentUri = (input) => createAction("SET_APP_CONTENT_URI", { ...input }, void 0, SetAppContentUriInputSchema, "global");
const setDiscussionsTo = (input) => createAction("SET_DISCUSSIONS_TO", { ...input }, void 0, SetDiscussionsToInputSchema, "global");
const setAppLicenseUri = (input) => createAction("SET_APP_LICENSE_URI", { ...input }, void 0, SetAppLicenseUriInputSchema, "global");
const setIsInactive = (input) => createAction("SET_IS_INACTIVE", { ...input }, void 0, SetIsInactiveInputSchema, "global");
const setCompletionRate = (input) => createAction("SET_COMPLETION_RATE", { ...input }, void 0, SetCompletionRateInputSchema, "global");
const setAppExtensions = (input) => createAction("SET_APP_EXTENSIONS", { ...input }, void 0, SetAppExtensionsInputSchema, "global");
const addAppSocial = (input) => createAction("ADD_APP_SOCIAL", { ...input }, void 0, AddAppSocialInputSchema, "global");
const removeAppSocial = (input) => createAction("REMOVE_APP_SOCIAL", { ...input }, void 0, RemoveAppSocialInputSchema, "global");
//#endregion
//#region document-models/grant-application/v1/gen/funding/creators.ts
var creators_exports$2 = /* @__PURE__ */ __exportAll({
	addFundsApproved: () => addFundsApproved,
	addFundsAsked: () => addFundsAsked,
	removeFundsAsked: () => removeFundsAsked,
	setFundsApprovedUsd: () => setFundsApprovedUsd,
	setFundsAskedUsd: () => setFundsAskedUsd,
	setPaymentTerm: () => setPaymentTerm,
	setPayoutAddress: () => setPayoutAddress
});
const addFundsAsked = (input) => createAction("ADD_FUNDS_ASKED", { ...input }, void 0, AddFundsAskedInputSchema, "global");
const removeFundsAsked = (input) => createAction("REMOVE_FUNDS_ASKED", { ...input }, void 0, RemoveFundsAskedInputSchema, "global");
const setFundsAskedUsd = (input) => createAction("SET_FUNDS_ASKED_USD", { ...input }, void 0, SetFundsAskedUsdInputSchema, "global");
const addFundsApproved = (input) => createAction("ADD_FUNDS_APPROVED", { ...input }, void 0, AddFundsApprovedInputSchema, "global");
const setFundsApprovedUsd = (input) => createAction("SET_FUNDS_APPROVED_USD", { ...input }, void 0, SetFundsApprovedUsdInputSchema, "global");
const setPayoutAddress = (input) => createAction("SET_PAYOUT_ADDRESS", { ...input }, void 0, SetPayoutAddressInputSchema, "global");
const setPaymentTerm = (input) => createAction("SET_PAYMENT_TERM", { ...input }, void 0, SetPaymentTermInputSchema, "global");
//#endregion
//#region document-models/grant-application/v1/gen/review/creators.ts
var creators_exports$1 = /* @__PURE__ */ __exportAll({
	approveApplication: () => approveApplication,
	conditionallyApprove: () => conditionallyApprove,
	markRevised: () => markRevised,
	openApplication: () => openApplication,
	rejectApplication: () => rejectApplication,
	requestRevision: () => requestRevision,
	startReview: () => startReview,
	submitApplication: () => submitApplication,
	withdrawApplication: () => withdrawApplication
});
const submitApplication = (input) => createAction("SUBMIT_APPLICATION", { ...input }, void 0, SubmitApplicationInputSchema, "global");
const openApplication = (input) => createAction("OPEN_APPLICATION", { ...input }, void 0, OpenApplicationInputSchema, "global");
const startReview = (input) => createAction("START_REVIEW", { ...input }, void 0, StartReviewInputSchema, "global");
const requestRevision = (input) => createAction("REQUEST_REVISION", { ...input }, void 0, RequestRevisionInputSchema, "global");
const markRevised = (input) => createAction("MARK_REVISED", { ...input }, void 0, MarkRevisedInputSchema, "global");
const approveApplication = (input) => createAction("APPROVE_APPLICATION", { ...input }, void 0, ApproveApplicationInputSchema, "global");
const conditionallyApprove = (input) => createAction("CONDITIONALLY_APPROVE", { ...input }, void 0, ConditionallyApproveInputSchema, "global");
const rejectApplication = (input) => createAction("REJECT_APPLICATION", { ...input }, void 0, RejectApplicationInputSchema, "global");
const withdrawApplication = (input) => createAction("WITHDRAW_APPLICATION", { ...input }, void 0, WithdrawApplicationInputSchema, "global");
//#endregion
//#region document-models/grant-application/v1/gen/payouts/creators.ts
var creators_exports = /* @__PURE__ */ __exportAll({
	markCompleted: () => markCompleted,
	recordPayout: () => recordPayout
});
const recordPayout = (input) => createAction("RECORD_PAYOUT", { ...input }, void 0, RecordPayoutInputSchema, "global");
const markCompleted = (input) => createAction("MARK_COMPLETED", { ...input }, void 0, MarkCompletedInputSchema, "global");
//#endregion
//#region document-models/grant-application/v1/actions.ts
/** Actions for the GrantApplication document model */
const actions = {
	...baseActions,
	...creators_exports$3,
	...creators_exports$2,
	...creators_exports$1,
	...creators_exports
};
//#endregion
//#region document-models/grant-application/v1/gen/document-type.ts
const grantApplicationDocumentType = "rfp-hub/grant-application";
//#endregion
//#region document-models/grant-application/v1/gen/document-schema.ts
/** Schema for validating the header object of a GrantApplication document */
const GrantApplicationDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal(grantApplicationDocumentType) });
/** Schema for validating the state object of a GrantApplication document */
const GrantApplicationPHStateSchema = BaseDocumentStateSchema.extend({ global: GrantApplicationStateSchema() });
const GrantApplicationDocumentSchema = object({
	header: GrantApplicationDocumentHeaderSchema,
	state: GrantApplicationPHStateSchema,
	initialState: GrantApplicationPHStateSchema
});
/** Simple helper function to check if a state object is a GrantApplication document state object */
function isGrantApplicationState(state) {
	return GrantApplicationPHStateSchema.safeParse(state).success;
}
/** Simple helper function to assert that a document state object is a GrantApplication document state object */
function assertIsGrantApplicationState(state) {
	GrantApplicationPHStateSchema.parse(state);
}
/** Simple helper function to check if a document is a GrantApplication document */
function isGrantApplicationDocument(document) {
	return GrantApplicationDocumentSchema.safeParse(document).success;
}
/** Simple helper function to assert that a document is a GrantApplication document */
function assertIsGrantApplicationDocument(document) {
	GrantApplicationDocumentSchema.parse(document);
}
//#endregion
//#region document-models/grant-application/v1/gen/utils.ts
const initialGlobalState = {
	grantPoolsURI: null,
	grantPoolId: null,
	grantPoolName: null,
	projectsURI: null,
	projectId: null,
	projectName: null,
	createdAt: null,
	contentURI: null,
	discussionsTo: null,
	licenseURI: null,
	isInactive: false,
	applicationCompletionRate: null,
	socials: [],
	fundsAsked: [],
	fundsAskedInUSD: null,
	fundsApproved: [],
	fundsApprovedInUSD: null,
	payoutAddress: null,
	status: "pending",
	payouts: [],
	extensions: null,
	paymentTerm: null,
	reviewStage: "DRAFT",
	feedbackNotes: null,
	revisionCount: 0,
	submitter: null,
	submittedAt: null,
	reviewedBy: null,
	reviewedAt: null
};
const initialLocalState = {};
const utils$1 = {
	fileExtension: "rfpa",
	createState(state) {
		return {
			...defaultBaseState(),
			global: {
				...initialGlobalState,
				...state?.global
			},
			local: {
				...initialLocalState,
				...state?.local
			}
		};
	},
	createDocument(state) {
		const document = baseCreateDocument(utils$1.createState, state);
		document.header.documentType = grantApplicationDocumentType;
		document.header.id = generateId();
		return document;
	},
	saveToFileHandle(document, input) {
		return baseSaveToFileHandle(document, input);
	},
	loadFromInput(input) {
		return baseLoadFromInput(input, reducer);
	},
	isStateOfType(state) {
		return isGrantApplicationState(state);
	},
	assertIsStateOfType(state) {
		return assertIsGrantApplicationState(state);
	},
	isDocumentOfType(document) {
		return isGrantApplicationDocument(document);
	},
	assertIsDocumentOfType(document) {
		return assertIsGrantApplicationDocument(document);
	}
};
//#endregion
//#region document-models/grant-application/v1/src/utils.ts
var utils_exports = /* @__PURE__ */ __exportAll({});
//#endregion
//#region document-models/grant-application/v1/utils.ts
/** Utils for the GrantApplication document model */
const utils = {
	...utils$1,
	...utils_exports
};
//#endregion
//#region document-models/grant-application/v1/module.ts
/** Document model module for the GrantApplication document type */
const GrantApplication = {
	version: 1,
	reducer,
	actions,
	utils,
	documentModel: createState(defaultBaseState(), documentModel)
};
//#endregion
export { AppSocialSchema as $, creators_exports$2 as A, SetProjectRefInputSchema as At, setAppExtensions as B, rejectApplication as C, SetDiscussionsToInputSchema as Ct, withdrawApplication as D, SetPaymentTermInputSchema as Dt, submitApplication as E, SetIsInactiveInputSchema as Et, setPayoutAddress as F, isDefinedNonNullAny as Ft, setIsInactive as G, setCompletionRate as H, addAppSocial as I, documentModel as It, reducer as J, setPoolRef as K, creators_exports$3 as L, setFundsApprovedUsd as M, SubmitApplicationInputSchema as Mt, setFundsAskedUsd as N, WithdrawApplicationInputSchema as Nt, addFundsApproved as O, SetPayoutAddressInputSchema as Ot, setPaymentTerm as P, definedNonNullAnySchema as Pt, AppFundingAmountSchema as Q, removeAppSocial as R, openApplication as S, SetCreatedAtInputSchema as St, startReview as T, SetFundsAskedUsdInputSchema as Tt, setCreatedAt as U, setAppLicenseUri as V, setDiscussionsTo as W, AddFundsApprovedInputSchema as X, AddAppSocialInputSchema as Y, AddFundsAskedInputSchema as Z, recordPayout as _, ReviewStageSchema as _t, utils$1 as a, GrantApplicationStateSchema as at, creators_exports$1 as b, SetAppLicenseUriInputSchema as bt, GrantApplicationPHStateSchema as c, OpenApplicationInputSchema as ct, isGrantApplicationDocument as d, PayoutSchema as dt, AppSubmitterSchema as et, isGrantApplicationState as f, RecordPayoutInputSchema as ft, markCompleted as g, RequestRevisionInputSchema as gt, creators_exports as h, RemoveFundsAskedInputSchema as ht, initialLocalState as i, ConditionallyApproveInputSchema as it, removeFundsAsked as j, StartReviewInputSchema as jt, addFundsAsked as k, SetPoolRefInputSchema as kt, assertIsGrantApplicationDocument as l, PaymentTermSchema as lt, actions as m, RemoveAppSocialInputSchema as mt, utils as n, ApplicationStatusSchema as nt, GrantApplicationDocumentHeaderSchema as o, MarkCompletedInputSchema as ot, grantApplicationDocumentType as p, RejectApplicationInputSchema as pt, setProjectRef as q, initialGlobalState as r, ApproveApplicationInputSchema as rt, GrantApplicationDocumentSchema as s, MarkRevisedInputSchema as st, GrantApplication as t, AppSubmitterTypeSchema as tt, assertIsGrantApplicationState as u, PayoutAddressSchema as ut, approveApplication as v, SetAppContentUriInputSchema as vt, requestRevision as w, SetFundsApprovedUsdInputSchema as wt, markRevised as x, SetCompletionRateInputSchema as xt, conditionallyApprove as y, SetAppExtensionsInputSchema as yt, setAppContentUri as z };

//# sourceMappingURL=module-Dnc2DHmS.mjs.map