/**
 * Per-project state tree — type definitions.
 *
 * Separated from project-state.svelte.ts to keep that file under 300 lines.
 * This file is plain .ts (no runes needed).
 */

import type { ProjectTab } from './project-tabs-store.svelte.ts';
export type { ProjectTab };

// ── Terminal ──────────────────────────────────────────────────────────────

export interface TermTab {
  id: string;
  title: string;
}

export interface TerminalState {
  tabs: TermTab[];
  activeTabId: string;
  expanded: boolean;
  nextId: number;
  mounted: Set<string>;
}

// ── Files ─────────────────────────────────────────────────────────────────

export interface DirEntry {
  name: string;
  type: 'file' | 'dir';
  size: number;
}

export interface FileState {
  childrenCache: Map<string, DirEntry[]>;
  openDirs: Set<string>;
  loadingDirs: Set<string>;
  selectedFile: string | null;
  fileContent: string | null;
  fileEncoding: 'utf8' | 'base64';
  fileSize: number;
  fileError: string | null;
  fileLoading: boolean;
  isDirty: boolean;
  editorContent: string;
  fileRequestToken: number;
  readMtimeMs: number;
  showConflictDialog: boolean;
}

// ── Comms ─────────────────────────────────────────────────────────────────

export interface Channel {
  id: string;
  name: string;
  groupId: string;
  createdBy: string;
  memberCount: number;
  createdAt: string;
}

export interface ChannelMessage {
  id: string;
  channelId: string;
  fromAgent: string;
  content: string;
  createdAt: string;
  senderName: string;
  senderRole: string;
}

export interface CommsAgent {
  id: string;
  name: string;
  role: string;
  groupId: string;
  tier: number;
  status: string;
  unreadCount: number;
}

export interface DM {
  id: string;
  fromAgent: string;
  toAgent: string;
  content: string;
  read: boolean;
  createdAt: string;
  senderName: string | null;
  senderRole: string | null;
}

export interface ChannelMember {
  agentId: string;
  name: string;
  role: string;
}

export interface CommsState {
  mode: 'channels' | 'dms';
  channels: Channel[];
  agents: CommsAgent[];
  activeChannelId: string | null;
  activeDmAgentId: string | null;
  channelMessages: ChannelMessage[];
  dmMessages: DM[];
  input: string;
  loading: boolean;
  channelMembers: ChannelMember[];
  showMembers: boolean;
}

// ── Tasks ─────────────────────────────────────────────────────────────────

export interface Task {
  id: string;
  title: string;
  description: string;
  status: string;
  priority: string;
  assignedTo: string | null;
  createdBy: string;
  groupId: string;
  version: number;
}

export interface TaskState {
  tasks: Task[];
  showCreateForm: boolean;
  newTitle: string;
  newDesc: string;
  newPriority: string;
  error: string;
  draggedTaskId: string | null;
  dragOverCol: string | null;
  pollToken: number;
}

// ── Tabs ──────────────────────────────────────────────────────────────────

export interface TabState {
  activeTab: ProjectTab;
  activatedTabs: Set<ProjectTab>;
}

// ── Root per-project state ────────────────────────────────────────────────

export interface ProjectState {
  terminals: TerminalState;
  files: FileState;
  comms: CommsState;
  tasks: TaskState;
  tab: TabState;
}
