import { RequestMethod } from '../common.types';
import { request } from '../request';

// Types
export interface Todo {
  id: string;
  userId: string;
  title: string;
  description: string;
  color: string;
  isActive: boolean;
  createdAt: string;
  updatedAt: string;
}

export interface TodoWithStats extends Todo {
  currentStreak: number;
  longestStreak: number;
  totalCompletions: number;
  lastCompletedAt?: string;
  completedToday: boolean;
}

export interface TodoCompletion {
  id: string;
  todoId: string;
  userId: string;
  completedAt: string;
  description: string;
  todo: Todo;
}

export interface DailyTodoSummary {
  date: string;
  todos: TodoWithStats[];
  completedCount: number;
  totalCount: number;
}

export interface CreateTodoRequest {
  title: string;
  description: string;
  color: string;
}

export interface UpdateTodoRequest {
  title: string;
  description: string;
  color: string;
}

export interface CompleteTodoRequest {
  description: string;
}

// API Functions
export const todoApi = {
  // Create a new todo
  createTodo: (data: CreateTodoRequest) =>
    request<Todo>(RequestMethod.POST, '/todo/create', data),

  // Update a todo
  updateTodo: (id: string, data: UpdateTodoRequest) =>
    request<Todo>(RequestMethod.PUT, `/todo/${id}`, data),

  // Delete a todo
  deleteTodo: (id: string) =>
    request<{ message: string }>(RequestMethod.DELETE, `/todo/${id}`),

  // Complete a todo
  completeTodo: (id: string, data: CompleteTodoRequest) =>
    request<{ message: string }>(RequestMethod.POST, `/todo/${id}/complete`, data),
};
