import api from 'src/config/api';

import {
  type CreateCategoryParams,
  type CreateCategoryResponse,
  type DeleteCategoryParams,
  type GetCategoriesParams,
  type GetCategoriesResponse,
  type UpdateCategoryParams,
  type UpdateCategoryStatusParams,
} from './types';

export const getCategories = ({ order, ...params }: GetCategoriesParams) =>
  api.get<GetCategoriesResponse>('/courses/categories', {
    params: {
      sortingOption: order,
      ...params,
    },
  });

export const createCategory = (params: CreateCategoryParams) =>
  api.post<CreateCategoryResponse>('courses/categories', params);

export const deleteCategory = ({ categoryId }: DeleteCategoryParams) =>
  api.delete(`courses/categories/${categoryId}`);

export const updateCategoryStatus = ({
  categoryId,
  ...params
}: UpdateCategoryStatusParams) =>
  api.put(`courses/categories/${categoryId}/status`, params);

export const updateCategory = ({
  categoryId,
  ...params
}: UpdateCategoryParams) => api.put(`courses/categories/${categoryId}`, params);
