/**
 * Lokale type-definisjoner for noder, edges, access og mixer-kanaler.
 *
 * Feltnavnene matcher JSON-formatet fra portvokterens WebSocket (camelCase).
 */

export interface Node {
	id: string;
	nodeKind: string;
	title: string;
	content: string;
	visibility: string;
	metadata: string;
	createdAt: number; // Unix microseconds
	createdBy: string;
}

export interface Edge {
	id: string;
	sourceId: string;
	targetId: string;
	edgeType: string;
	metadata: string;
	system: boolean;
	createdAt: number;
	createdBy: string;
}

export interface NodeAccess {
	id: string; // "subjectId:objectId"
	subjectId: string;
	objectId: string;
	access: string;
	viaEdge: string;
}

export interface MixerChannel {
	id: string; // "roomId:targetUserId"
	roomId: string;
	targetUserId: string;
	gain: number;
	isMuted: boolean;
	activeEffects: string; // JSON
	role: string;
	updatedBy: string;
	updatedAt: number;
}

// ---------------------------------------------------------------------------
// WebSocket-meldingstyper fra portvokteren
// ---------------------------------------------------------------------------

export interface WsNodeChanged {
	type: 'node_changed';
	op: string;
	id: string;
	kind: string;
	node?: Node;
}

export interface WsEdgeChanged {
	type: 'edge_changed';
	op: string;
	id: string;
	source_id: string;
	target_id: string;
	edge_type: string;
	edge?: Edge;
}

export interface WsAccessChanged {
	type: 'access_changed';
	op: string;
	subject_id: string;
	object_id: string;
	access?: string;
	row?: NodeAccess;
}

export interface WsMixerChannelChanged {
	type: 'mixer_channel_changed';
	op: string;
	room_id: string;
	target_user_id: string;
	channel?: MixerChannel;
}

export interface WsInitialSync {
	type: 'initial_sync';
	nodes: Node[];
	edges: Edge[];
	access: NodeAccess[];
	mixer_channels: MixerChannel[];
}

export type WsMessage =
	| WsNodeChanged
	| WsEdgeChanged
	| WsAccessChanged
	| WsMixerChannelChanged
	| WsInitialSync;
