import type { Database, Tables, TablesInsert, TablesUpdate } from "./database.types.js";
import type { RemoveNullFromObject } from "./utils.js";

export type TaskStatus = "todo" | "in_progress" | "in_review" | "done";

export type KanbanTask = RemoveNullFromObject<
  Tables<"tasks_with_assignee">,
  "id" | "tablo_id" | "is_parent"
>;

export type Etape = RemoveNullFromObject<
  Tables<"tasks">,
  "id" | "tablo_id" | "title" | "is_parent"
>;

export interface KanbanColumn {
  id: string;
  title: string;
  status: TaskStatus;
  position: number;
  color?: string;
  task_limit?: number;
  tasks: KanbanTask[];
}

export interface KanbanBoard {
  id: string;
  name: string;
  description?: string;
  tablo_id: string;
  columns: KanbanColumn[];
  created_at: string;
  updated_at: string;
}

export interface TaskComment {
  id: string;
  task_id: string;
  user_id: string;
  user_name: string;
  user_avatar?: string;
  content: string;
  created_at: string;
  updated_at: string;
}

export interface TaskAttachment {
  id: string;
  task_id: string;
  filename: string;
  file_url: string;
  file_size: number;
  file_type: string;
  uploaded_by: string;
  uploaded_at: string;
}

export type TaskStatusType = Database["public"]["Enums"]["task_status"];

export type KanbanTaskInsert = TablesInsert<"tasks">;

export type KanbanTaskUpdate = TablesUpdate<"tasks">;

export interface KanbanColumnUpdate {
  title?: string;
  position?: number;
  color?: string;
  task_limit?: number;
}

// UI-specific types for drag and drop
export interface DragItem {
  id: string;
  type: "task" | "column";
  sourceColumnId: string;
  sourceIndex: number;
}

export interface DropResult {
  draggedId: string;
  source: {
    columnId: string;
    index: number;
  };
  destination: {
    columnId: string;
    index: number;
  };
}

export interface KanbanSort {
  field: "priority" | "created_at" | "updated_at" | "due_date" | "story_points";
  direction: "asc" | "desc";
}
