import { apiClient } from './api';
import {
  Publication,
  PublishingStep,
  PaginatedResponse,
  ApiResponse
} from '../types';

export const publicationService = {
  async getPublications(
    page: number = 1,
    pageSize: number = 10
  ): Promise<PaginatedResponse<Publication>> {
    return apiClient.getPaginated('/publications', { page, pageSize });
  },

  async getPublication(id: number): Promise<ApiResponse<Publication>> {
    return apiClient.get(`/publications/${id}`);
  },

  async getPublicationSteps(publicationId: number): Promise<ApiResponse<PublishingStep[]>> {
    return apiClient.get(`/publications/${publicationId}/steps`);
  },

  async getActivePublications(): Promise<ApiResponse<Publication[]>> {
    return apiClient.get('/publications/active');
  },

  async cancelPublication(id: number): Promise<ApiResponse<void>> {
    return apiClient.post(`/publications/${id}/cancel`);
  },

  async retryPublication(id: number): Promise<ApiResponse<void>> {
    return apiClient.post(`/publications/${id}/retry`);
  },
};