/**
 * Core data types for the Canvas Platform
 */

export type Week = 1 | 2 | 3;
export type Day = 1 | 2 | 3 | 4 | 5;

export interface CanvasTemplate {
  id: string;
  templateId: string;
  title: string;
  subtitle?: string;
  week: Week;
  day: Day;
  exerciseNumber: number;
  category: CanvasCategory;
  inputFields: FieldDefinition[];
  hasDragDrop?: boolean;
}

export type CanvasCategory =
  | "exploration"
  | "ideation"
  | "prototyping"
  | "validation"
  | "synthesis"
  | "terrain";

export interface FieldDefinition {
  id: string;
  type: FieldType;
  label: string;
  placeholder?: string;
  required?: boolean;
  maxLength?: number;
  rows?: number;
  gridPosition?: { x: number; y: number; width: number; height: number };
}

export type FieldType =
  | "text"
  | "textarea"
  | "list"
  | "image"
  | "drawing"
  | "date"
  | "select";

export interface CanvasData {
  id: string;
  templateId: string;
  week: Week;
  day: Day;
  title: string;
  fields: Record<string, FieldValue>;
  elements?: DraggableElement[];
  metadata: CanvasMetadata;
  createdAt: number;
  updatedAt: number;
}

export type FieldValue = string | string[] | null;

export interface DraggableElement {
  id: string;
  type: ElementType;
  position: Position;
  label: string;
  color?: string;
  connections?: string[];
}

export type ElementType =
  | "stakeholder"
  | "signal"
  | "concept"
  | "action"
  | "note";

export interface Position {
  x: number;
  y: number;
}


export type CanvasStatus = 'not_started' | 'started' | 'finished';

export interface CanvasMetadata {
  team?: string;
  date?: string;
  facilitator?: string;
  sessionId?: string;
  status?: CanvasStatus;
  [key: string]: unknown;
}

// UI State Types
export interface TabState {
  activeWeek: Week;
}

export interface EditorState {
  isEditing: boolean;
  activeFieldId: string | null;
  hasUnsavedChanges: boolean;
}

// Collaboration Types
export interface Cursor {
  id: string;
  name: string;
  color: string;
  position: Position;
}

export interface Presence {
  id: string;
  name: string;
  color: string;
  cursor: Position | null;
  activeFieldId: string | null;
}
