import { apiClient } from './api';
import {
  Project,
  Build,
  BuildCommit,
  BuildFilter,
  PaginatedResponse,
  ApiResponse
} from '../types';

export const projectService = {
  async getProjects(): Promise<ApiResponse<Project[]>> {
    return apiClient.get('/projects');
  },

  async getProject(id: number): Promise<ApiResponse<Project>> {
    return apiClient.get(`/projects/${id}`);
  },

  async getProjectBuilds(
    projectId: number,
    page: number = 1,
    pageSize: number = 10,
    filter?: BuildFilter
  ): Promise<PaginatedResponse<Build>> {
    return apiClient.getPaginated(`/projects/${projectId}/builds`, {
      page,
      pageSize,
      ...filter,
    });
  },

  async getBuild(buildId: number): Promise<ApiResponse<Build>> {
    return apiClient.get(`/builds/${buildId}`);
  },

  async getBuildCommits(buildId: number): Promise<ApiResponse<BuildCommit[]>> {
    return apiClient.get(`/builds/${buildId}/commits`);
  },

  async getProjectStatus(): Promise<ApiResponse<Project[]>> {
    return apiClient.get('/projects/status');
  },
};