import http from '@/services/http';
import type {
  ZohoProjectsApiResponse,
  ZohoTasksApiResponse,
  ZohoIssuesApiResponse,
  ZohoPhasesApiResponse,
  ZohoProjectsFilters,
} from '../types/ZohoProjectsTypes';

export interface ZohoProjectsSearchParams {
  provider?: string;
  service?: string;
  resource?: string;
  portal_id?: string;
  page?: number;
  limit?: number;
  status?: string;
  project_type?: string;
}

const ZOHO_PROJECTS_BASE_URL = '/api/v1/integrations';

export const zohoProjectsAPI = {
  // Get all projects with pagination and filters
  getAllProjects: (params?: ZohoProjectsSearchParams) => {
    const queryParams = {
      provider: 'zoho',
      service: 'projects',
      resource: 'projects',
      page: 1,
      limit: 20,
      ...params,
    };
    return http.get<ZohoProjectsApiResponse>(`${ZOHO_PROJECTS_BASE_URL}/zoho/projects/all-projects`, queryParams);
  },

  // Get all project tasks with pagination
  getAllProjectTasks: (portalId: string, params?: ZohoProjectsSearchParams) => {
    const queryParams = {
      provider: 'zoho',
      portal_id: portalId,
      page: 1,
      limit: 50,
      ...params,
    };
    return http.get<ZohoTasksApiResponse>(`${ZOHO_PROJECTS_BASE_URL}/zoho/projects/all-project-tasks`, queryParams);
  },

  // Get all project issues with pagination
  getAllProjectIssues: (portalId: string, params?: ZohoProjectsSearchParams) => {
    const queryParams = {
      provider: 'zoho',
      portal_id: portalId,
      page: 1,
      limit: 50,
      ...params,
    };
    return http.get<ZohoIssuesApiResponse>(`${ZOHO_PROJECTS_BASE_URL}/zoho/projects/all-project-issues`, queryParams);
  },

  // Get all project phases with pagination
  getAllProjectPhases: (portalId: string, params?: ZohoProjectsSearchParams) => {
    const queryParams = {
      provider: 'zoho',
      portal_id: portalId,
      page: 1,
      limit: 50,
      ...params,
    };
    return http.get<ZohoPhasesApiResponse>(`${ZOHO_PROJECTS_BASE_URL}/zoho/projects/all-project-phases`, queryParams);
  },

  // Get projects by filters
  getProjectsByFilters: (filters: ZohoProjectsFilters, params?: ZohoProjectsSearchParams) => {
    const queryParams = {
      provider: 'zoho',
      service: 'projects',
      resource: 'projects',
      page: 1,
      limit: 20,
      ...filters,
      ...params,
    };
    return http.get<ZohoProjectsApiResponse>(`${ZOHO_PROJECTS_BASE_URL}/zoho/projects/all-projects`, queryParams);
  },
};


