import { useApi } from './useApi'
import type { ApiMyTaskRow, MyTaskListQuery } from '@/types/my-task'
import type { Paginated } from '@/types/pagination'

// 내 업무 API Composable — 프로젝트 횡단 집계(담당/지시), 검색/프로젝트/정렬 + 오프셋 페이지네이션
export function useMyTask() {
  const api = useApi()

  // 내가 담당인 업무
  async function assigned(
    page = 1,
    size = 20,
    query: MyTaskListQuery = {},
  ): Promise<Paginated<ApiMyTaskRow>> {
    return (await api.get('/tasks/assigned', {
      params: { ...query, page, size },
    })) as unknown as Paginated<ApiMyTaskRow>
  }

  // 내가 지시한 업무
  async function issued(
    page = 1,
    size = 20,
    query: MyTaskListQuery = {},
  ): Promise<Paginated<ApiMyTaskRow>> {
    return (await api.get('/tasks/issued', {
      params: { ...query, page, size },
    })) as unknown as Paginated<ApiMyTaskRow>
  }

  return { assigned, issued }
}
