import { serviceApi } from './api';
import {
  AxiosResponse,
  ServiceResponse,
  ServicesResponse,
  ServiceCall,
  CalendarEventsResponse
} from '../types/models';


export const serviceService = {
  // CRUD operations
  create: (data: any): Promise<AxiosResponse<ServiceResponse>> =>
    serviceApi.post('/service/create', data),

  getById: (id: number): Promise<AxiosResponse<ServiceResponse>> =>
    serviceApi.get(`/service/${id}`),

  update: (id: number, data: any): Promise<AxiosResponse<ServiceResponse>> =>
    serviceApi.put(`/service/update/${id}`, data),

  delete: (id: number): Promise<AxiosResponse<{ ok: boolean }>> =>
    serviceApi.delete(`/service/delete/${id}`),

  // List operations
  getAll: (): Promise<AxiosResponse<CalendarEventsResponse>> =>
    serviceApi.get('/service/all'),

  getToday: (): Promise<AxiosResponse<ServicesResponse>> =>
    serviceApi.get('/service/today'),

  getUpcoming: (): Promise<AxiosResponse<ServicesResponse>> =>
    serviceApi.get('/service/upcoming'),

  getPast: (): Promise<AxiosResponse<ServicesResponse>> =>
    serviceApi.get('/service/past'),

  getForCustomer: (customerId: number): Promise<AxiosResponse<ServicesResponse>> =>
    serviceApi.get(`/service/for-customer/${customerId}`),

  // Cost management
  updateCost: (id: number, data: any): Promise<AxiosResponse<{ ok: boolean; service: ServiceCall }>> =>
    serviceApi.put(`/service/update-cost/${id}`, data),

  // Parts
  getPartsForCustomer: (customerId: number): Promise<AxiosResponse<{ ok: boolean; parts: any[] }>> =>
    serviceApi.get(`/service/parts/customer/${customerId}`),

  updateParts: (id: number, data: any): Promise<AxiosResponse<{ ok: boolean }>> =>
    serviceApi.post(`/service/parts/update/${id}`, data),

  // Service plans
  plans: {
    getActive: (): Promise<AxiosResponse<{ ok: boolean; plans: any[] }>> =>
      serviceApi.get('/service/plans/active'),

    getForCustomer: (customerId: number): Promise<AxiosResponse<{ ok: boolean; plan: any }>> =>
      serviceApi.get(`/service/plans/customer/${customerId}`),

    create: (data: any): Promise<AxiosResponse<{ ok: boolean }>> =>
      serviceApi.post('/service/plans/create', data),

    update: (id: number, data: any): Promise<AxiosResponse<{ ok: boolean }>> =>
      serviceApi.put(`/service/plans/update/${id}`, data),

    delete: (id: number): Promise<AxiosResponse<{ ok: boolean }>> =>
      serviceApi.delete(`/service/plans/delete/${id}`),
  },
};

export default serviceService;
