import api from 'src/config/api';
import {
  type View,
  type ViewListItem,
} from 'src/pages/dashboard/serviceManagement/types';
import { type Pagination } from 'src/types/services';

export const deleteView = (viewId: string) =>
  api.delete(`workflows/views/${viewId}`);

export const renameView = (viewId: string, name: string) =>
  api.patch(`workflows/views/${viewId}/name`, { name });

export const reorderView = (viewId: string, position: number) =>
  api.patch(`workflows/views/${viewId}/position`, { position });

export const editView = (viewId: string, body: unknown) =>
  api.put(`workflows/views/${viewId}`, body);

export const getViews = (page: number, limit = 20) =>
  api.get<Pagination<ViewListItem>>('workflows/views', {
    params: {
      page,
      limit,
    },
  });

export const getView = (viewId: string) =>
  api.get<View>(`workflows/views/${viewId}`);

export const createView = (body: unknown) =>
  api.post<ViewListItem>('workflows/views', body);
