import { n as __exportAll } from "./chunk-YKewjYmz.js";
import { D as object, O as string, S as array, T as literal, _ as generateId, a as BaseDocumentHeaderSchema, b as _enum, c as baseCreateDocument, f as createAction, g as defaultBaseState, h as createState, j as datetime, l as baseLoadFromInput, m as createReducer, o as BaseDocumentStateSchema, s as baseActions, u as baseSaveToFileHandle, v as isDocumentAction, w as lazy, x as any } from "./dist-Dacf6lFH.js";
//#region document-models/channel/v1/gen/document-model.ts
const documentModel = {
	id: "powerchat/channel",
	name: "Channel",
	author: {
		name: "Powerhouse",
		website: "https://www.powerhouse.inc/"
	},
	extension: "chat",
	description: "Channel permissions, participants, and configuration for PowerChat.",
	specifications: [{
		state: {
			local: {
				schema: "",
				examples: [],
				initialValue: ""
			},
			global: {
				schema: "enum ChannelVisibility {\n  PUBLIC\n  PRIVATE\n}\n\nenum ParticipantRole {\n  OWNER\n  ADMIN\n  MEMBER\n  GUEST\n}\n\nenum ChannelType {\n  TEXT\n  VOICE\n}\n\ntype Participant {\n  id: OID!\n  name: String!\n  avatar: String\n  role: ParticipantRole!\n  joinedAt: DateTime!\n}\n\ntype ChannelState {\n  name: String\n  description: String\n  topic: String\n  channelType: ChannelType!\n  visibility: ChannelVisibility!\n  participants: [Participant!]!\n}",
				examples: [],
				initialValue: "{\"name\": null, \"description\": null, \"topic\": null, \"channelType\": \"TEXT\", \"visibility\": \"PUBLIC\", \"participants\": []}"
			}
		},
		modules: [{
			id: "mod-channel",
			name: "channel",
			description: "Channel metadata and settings operations",
			operations: [
				{
					id: "op-set-channel-name",
					name: "SET_CHANNEL_NAME",
					description: "Sets the name of the channel",
					schema: "input SetChannelNameInput {\n  name: String!\n}",
					template: "Sets the name of the channel",
					reducer: "state.name = action.input.name;",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "op-set-channel-description",
					name: "SET_CHANNEL_DESCRIPTION",
					description: "Sets the description of the channel",
					schema: "input SetChannelDescriptionInput {\n  description: String!\n}",
					template: "Sets the description of the channel",
					reducer: "state.description = action.input.description;",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "op-set-channel-visibility",
					name: "SET_CHANNEL_VISIBILITY",
					description: "Sets the channel visibility to public or private",
					schema: "input SetChannelVisibilityInput {\n  visibility: ChannelVisibility!\n}",
					template: "Sets the channel visibility to public or private",
					reducer: "state.visibility = action.input.visibility;",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "op-set-channel-topic",
					name: "SET_CHANNEL_TOPIC",
					description: "Sets the topic displayed in the channel header",
					schema: "input SetChannelTopicInput {\n  topic: String!\n}",
					template: "Sets the topic displayed in the channel header",
					reducer: "state.topic = action.input.topic;",
					errors: [],
					examples: [],
					scope: "global"
				},
				{
					id: "op-set-channel-type",
					name: "SET_CHANNEL_TYPE",
					description: "Sets the channel type (text or voice)",
					schema: "input SetChannelTypeInput {\n  channelType: ChannelType!\n}",
					template: "Sets the channel type (text or voice)",
					reducer: "state.channelType = action.input.channelType;",
					errors: [],
					examples: [],
					scope: "global"
				}
			]
		}, {
			id: "mod-participants",
			name: "participants",
			description: "Participant management operations",
			operations: [
				{
					id: "op-add-participant",
					name: "ADD_PARTICIPANT",
					description: "Adds a new participant to the channel",
					schema: "input AddParticipantInput {\n  id: OID!\n  name: String!\n  avatar: String\n  role: ParticipantRole!\n  joinedAt: DateTime!\n}",
					template: "Adds a new participant to the channel",
					reducer: "const existing = state.participants.find(p => p.id === action.input.id);\nif (existing) {\n  throw new DuplicateParticipantError(`Participant ${action.input.id} already exists`);\n}\nstate.participants.push({\n  id: action.input.id,\n  name: action.input.name,\n  avatar: action.input.avatar || null,\n  role: action.input.role,\n  joinedAt: action.input.joinedAt,\n});",
					errors: [{
						id: "err-duplicate-participant",
						name: "DuplicateParticipantError",
						code: "DUPLICATE_PARTICIPANT",
						description: "Participant already exists in the channel",
						template: ""
					}],
					examples: [],
					scope: "global"
				},
				{
					id: "op-remove-participant",
					name: "REMOVE_PARTICIPANT",
					description: "Removes a participant from the channel",
					schema: "input RemoveParticipantInput {\n  participantId: OID!\n}",
					template: "Removes a participant from the channel",
					reducer: "const index = state.participants.findIndex(p => p.id === action.input.participantId);\nif (index === -1) {\n  throw new ParticipantNotFoundError(`Participant ${action.input.participantId} not found`);\n}\nstate.participants.splice(index, 1);",
					errors: [{
						id: "err-participant-not-found-remove",
						name: "ParticipantNotFoundError",
						code: "PARTICIPANT_NOT_FOUND",
						description: "Participant not found in the channel",
						template: ""
					}],
					examples: [],
					scope: "global"
				},
				{
					id: "op-update-participant-role",
					name: "UPDATE_PARTICIPANT_ROLE",
					description: "Updates the role of a participant",
					schema: "input UpdateParticipantRoleInput {\n  participantId: OID!\n  role: ParticipantRole!\n}",
					template: "Updates the role of a participant",
					reducer: "const participant = state.participants.find(p => p.id === action.input.participantId);\nif (!participant) {\n  throw new ParticipantNotFoundError(`Participant ${action.input.participantId} not found`);\n}\nparticipant.role = action.input.role;",
					errors: [{
						id: "err-participant-not-found-role",
						name: "ParticipantNotFoundError",
						code: "PARTICIPANT_NOT_FOUND",
						description: "Participant not found in the channel",
						template: ""
					}],
					examples: [],
					scope: "global"
				}
			]
		}],
		version: 1,
		changeLog: []
	}]
};
//#endregion
//#region document-models/channel/v1/src/reducers/channel.ts
const channelChannelOperations = {
	setChannelNameOperation(state, action) {
		state.name = action.input.name;
	},
	setChannelDescriptionOperation(state, action) {
		state.description = action.input.description;
	},
	setChannelVisibilityOperation(state, action) {
		state.visibility = action.input.visibility;
	},
	setChannelTopicOperation(state, action) {
		state.topic = action.input.topic;
	},
	setChannelTypeOperation(state, action) {
		state.channelType = action.input.channelType;
	}
};
//#endregion
//#region document-models/channel/v1/gen/participants/error.ts
var DuplicateParticipantError = class extends Error {
	errorCode = "DuplicateParticipantError";
	constructor(message = "DuplicateParticipantError") {
		super(message);
	}
};
var ParticipantNotFoundError = class extends Error {
	errorCode = "ParticipantNotFoundError";
	constructor(message = "ParticipantNotFoundError") {
		super(message);
	}
};
//#endregion
//#region document-models/channel/v1/src/reducers/participants.ts
const channelParticipantsOperations = {
	addParticipantOperation(state, action) {
		if (state.participants.find((p) => p.id === action.input.id)) throw new DuplicateParticipantError(`Participant ${action.input.id} already exists`);
		state.participants.push({
			id: action.input.id,
			name: action.input.name,
			avatar: action.input.avatar || null,
			role: action.input.role,
			joinedAt: action.input.joinedAt
		});
	},
	removeParticipantOperation(state, action) {
		const index = state.participants.findIndex((p) => p.id === action.input.participantId);
		if (index === -1) throw new ParticipantNotFoundError(`Participant ${action.input.participantId} not found`);
		state.participants.splice(index, 1);
	},
	updateParticipantRoleOperation(state, action) {
		const participant = state.participants.find((p) => p.id === action.input.participantId);
		if (!participant) throw new ParticipantNotFoundError(`Participant ${action.input.participantId} not found`);
		participant.role = action.input.role;
	}
};
//#endregion
//#region document-models/channel/v1/gen/schema/zod.ts
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
const definedNonNullAnySchema = any().refine((v) => isDefinedNonNullAny(v));
const ChannelTypeSchema = _enum(["TEXT", "VOICE"]);
const ChannelVisibilitySchema = _enum(["PRIVATE", "PUBLIC"]);
const ParticipantRoleSchema = _enum([
	"ADMIN",
	"GUEST",
	"MEMBER",
	"OWNER"
]);
function AddParticipantInputSchema() {
	return object({
		avatar: string().nullish(),
		id: string(),
		joinedAt: datetime(),
		name: string(),
		role: ParticipantRoleSchema
	});
}
function ChannelStateSchema() {
	return object({
		__typename: literal("ChannelState").optional(),
		channelType: ChannelTypeSchema,
		description: string().nullish(),
		name: string().nullish(),
		participants: array(lazy(() => ParticipantSchema())),
		topic: string().nullish(),
		visibility: ChannelVisibilitySchema
	});
}
function ParticipantSchema() {
	return object({
		__typename: literal("Participant").optional(),
		avatar: string().nullish(),
		id: string(),
		joinedAt: datetime(),
		name: string(),
		role: ParticipantRoleSchema
	});
}
function RemoveParticipantInputSchema() {
	return object({ participantId: string() });
}
function SetChannelDescriptionInputSchema() {
	return object({ description: string() });
}
function SetChannelNameInputSchema() {
	return object({ name: string() });
}
function SetChannelTopicInputSchema() {
	return object({ topic: string() });
}
function SetChannelTypeInputSchema() {
	return object({ channelType: ChannelTypeSchema });
}
function SetChannelVisibilityInputSchema() {
	return object({ visibility: ChannelVisibilitySchema });
}
function UpdateParticipantRoleInputSchema() {
	return object({
		participantId: string(),
		role: ParticipantRoleSchema
	});
}
//#endregion
//#region document-models/channel/v1/gen/reducer.ts
const stateReducer = (state, action, dispatch) => {
	if (isDocumentAction(action)) return state;
	switch (action.type) {
		case "SET_CHANNEL_NAME":
			SetChannelNameInputSchema().parse(action.input);
			channelChannelOperations.setChannelNameOperation(state[action.scope], action, dispatch);
			break;
		case "SET_CHANNEL_DESCRIPTION":
			SetChannelDescriptionInputSchema().parse(action.input);
			channelChannelOperations.setChannelDescriptionOperation(state[action.scope], action, dispatch);
			break;
		case "SET_CHANNEL_VISIBILITY":
			SetChannelVisibilityInputSchema().parse(action.input);
			channelChannelOperations.setChannelVisibilityOperation(state[action.scope], action, dispatch);
			break;
		case "SET_CHANNEL_TOPIC":
			SetChannelTopicInputSchema().parse(action.input);
			channelChannelOperations.setChannelTopicOperation(state[action.scope], action, dispatch);
			break;
		case "SET_CHANNEL_TYPE":
			SetChannelTypeInputSchema().parse(action.input);
			channelChannelOperations.setChannelTypeOperation(state[action.scope], action, dispatch);
			break;
		case "ADD_PARTICIPANT":
			AddParticipantInputSchema().parse(action.input);
			channelParticipantsOperations.addParticipantOperation(state[action.scope], action, dispatch);
			break;
		case "REMOVE_PARTICIPANT":
			RemoveParticipantInputSchema().parse(action.input);
			channelParticipantsOperations.removeParticipantOperation(state[action.scope], action, dispatch);
			break;
		case "UPDATE_PARTICIPANT_ROLE":
			UpdateParticipantRoleInputSchema().parse(action.input);
			channelParticipantsOperations.updateParticipantRoleOperation(state[action.scope], action, dispatch);
			break;
		default: return state;
	}
};
const reducer = createReducer(stateReducer);
//#endregion
//#region document-models/channel/v1/gen/channel/creators.ts
var creators_exports$1 = /* @__PURE__ */ __exportAll({
	setChannelDescription: () => setChannelDescription,
	setChannelName: () => setChannelName,
	setChannelTopic: () => setChannelTopic,
	setChannelType: () => setChannelType,
	setChannelVisibility: () => setChannelVisibility
});
const setChannelName = (input) => createAction("SET_CHANNEL_NAME", { ...input }, void 0, SetChannelNameInputSchema, "global");
const setChannelDescription = (input) => createAction("SET_CHANNEL_DESCRIPTION", { ...input }, void 0, SetChannelDescriptionInputSchema, "global");
const setChannelVisibility = (input) => createAction("SET_CHANNEL_VISIBILITY", { ...input }, void 0, SetChannelVisibilityInputSchema, "global");
const setChannelTopic = (input) => createAction("SET_CHANNEL_TOPIC", { ...input }, void 0, SetChannelTopicInputSchema, "global");
const setChannelType = (input) => createAction("SET_CHANNEL_TYPE", { ...input }, void 0, SetChannelTypeInputSchema, "global");
//#endregion
//#region document-models/channel/v1/gen/participants/creators.ts
var creators_exports = /* @__PURE__ */ __exportAll({
	addParticipant: () => addParticipant,
	removeParticipant: () => removeParticipant,
	updateParticipantRole: () => updateParticipantRole
});
const addParticipant = (input) => createAction("ADD_PARTICIPANT", { ...input }, void 0, AddParticipantInputSchema, "global");
const removeParticipant = (input) => createAction("REMOVE_PARTICIPANT", { ...input }, void 0, RemoveParticipantInputSchema, "global");
const updateParticipantRole = (input) => createAction("UPDATE_PARTICIPANT_ROLE", { ...input }, void 0, UpdateParticipantRoleInputSchema, "global");
//#endregion
//#region document-models/channel/v1/actions.ts
/** Actions for the Channel document model */
const actions = {
	...baseActions,
	...creators_exports$1,
	...creators_exports
};
//#endregion
//#region document-models/channel/v1/gen/document-type.ts
const channelDocumentType = "powerchat/channel";
//#endregion
//#region document-models/channel/v1/gen/document-schema.ts
/** Schema for validating the header object of a Channel document */
const ChannelDocumentHeaderSchema = BaseDocumentHeaderSchema.extend({ documentType: literal(channelDocumentType) });
/** Schema for validating the state object of a Channel document */
const ChannelPHStateSchema = BaseDocumentStateSchema.extend({ global: ChannelStateSchema() });
const ChannelDocumentSchema = object({
	header: ChannelDocumentHeaderSchema,
	state: ChannelPHStateSchema,
	initialState: ChannelPHStateSchema
});
/** Simple helper function to check if a state object is a Channel document state object */
function isChannelState(state) {
	return ChannelPHStateSchema.safeParse(state).success;
}
/** Simple helper function to assert that a document state object is a Channel document state object */
function assertIsChannelState(state) {
	ChannelPHStateSchema.parse(state);
}
/** Simple helper function to check if a document is a Channel document */
function isChannelDocument(document) {
	return ChannelDocumentSchema.safeParse(document).success;
}
/** Simple helper function to assert that a document is a Channel document */
function assertIsChannelDocument(document) {
	ChannelDocumentSchema.parse(document);
}
//#endregion
//#region document-models/channel/v1/gen/utils.ts
const initialGlobalState = {
	name: null,
	description: null,
	topic: null,
	channelType: "TEXT",
	visibility: "PUBLIC",
	participants: []
};
const initialLocalState = {};
const utils$1 = {
	fileExtension: "chat",
	createState(state) {
		return {
			...defaultBaseState(),
			global: {
				...initialGlobalState,
				...state?.global
			},
			local: {
				...initialLocalState,
				...state?.local
			}
		};
	},
	createDocument(state) {
		const document = baseCreateDocument(utils$1.createState, state);
		document.header.documentType = channelDocumentType;
		document.header.id = generateId();
		return document;
	},
	saveToFileHandle(document, input) {
		return baseSaveToFileHandle(document, input);
	},
	loadFromInput(input) {
		return baseLoadFromInput(input, reducer);
	},
	isStateOfType(state) {
		return isChannelState(state);
	},
	assertIsStateOfType(state) {
		return assertIsChannelState(state);
	},
	isDocumentOfType(document) {
		return isChannelDocument(document);
	},
	assertIsDocumentOfType(document) {
		return assertIsChannelDocument(document);
	}
};
//#endregion
//#region document-models/channel/v1/src/utils.ts
var utils_exports = /* @__PURE__ */ __exportAll({});
//#endregion
//#region document-models/channel/v1/utils.ts
/** Utils for the Channel document model */
const utils = {
	...utils$1,
	...utils_exports
};
//#endregion
//#region document-models/channel/v1/module.ts
/** Document model module for the Channel document type */
const Channel = {
	version: 1,
	reducer,
	actions,
	utils,
	documentModel: createState(defaultBaseState(), documentModel)
};
//#endregion
export { ParticipantRoleSchema as A, isDefinedNonNullAny as B, setChannelType as C, ChannelStateSchema as D, AddParticipantInputSchema as E, SetChannelTopicInputSchema as F, SetChannelTypeInputSchema as I, SetChannelVisibilityInputSchema as L, RemoveParticipantInputSchema as M, SetChannelDescriptionInputSchema as N, ChannelTypeSchema as O, SetChannelNameInputSchema as P, UpdateParticipantRoleInputSchema as R, setChannelTopic as S, reducer as T, documentModel as V, removeParticipant as _, utils$1 as a, setChannelDescription as b, ChannelPHStateSchema as c, isChannelDocument as d, isChannelState as f, creators_exports as g, addParticipant as h, initialLocalState as i, ParticipantSchema as j, ChannelVisibilitySchema as k, assertIsChannelDocument as l, actions as m, utils as n, ChannelDocumentHeaderSchema as o, channelDocumentType as p, initialGlobalState as r, ChannelDocumentSchema as s, Channel as t, assertIsChannelState as u, updateParticipantRole as v, setChannelVisibility as w, setChannelName as x, creators_exports$1 as y, definedNonNullAnySchema as z };

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