import { apiClient } from './api';
import {
  Package,
  CreatePackageRequest,
  PackageFilter,
  PaginatedResponse,
  ApiResponse
} from '../types';

export const packageService = {
  async getPackages(
    page: number = 1,
    pageSize: number = 10,
    filter?: PackageFilter
  ): Promise<PaginatedResponse<Package>> {
    return apiClient.getPaginated('/packages', {
      page,
      pageSize,
      ...filter,
    });
  },

  async getPackage(id: number): Promise<ApiResponse<Package>> {
    return apiClient.get(`/packages/${id}`);
  },

  async createPackage(request: CreatePackageRequest): Promise<ApiResponse<Package>> {
    return apiClient.post('/packages', request);
  },

  async updatePackage(id: number, request: Partial<CreatePackageRequest>): Promise<ApiResponse<Package>> {
    return apiClient.put(`/packages/${id}`, request);
  },

  async deletePackage(id: number): Promise<ApiResponse<void>> {
    return apiClient.delete(`/packages/${id}`);
  },

  async publishPackage(packageId: number, buildId: number): Promise<ApiResponse<void>> {
    return apiClient.post(`/packages/${packageId}/publish`, { buildId });
  },
};