import { requestClient } from '#/api/request';

export namespace classificationApi {
  export interface classification {
    id: number;
    org_id: string;
    name: string;
    desc: string;
    products: classification[];
    created_at: string;
    updated_at: string;
  }
  export interface getClassification {
    list: classification[];
  }
  export interface createClassification {
    name: string;
    desc: string;
    org_id: string;
  }
  export interface updateClassification {
    name: string;
    desc: string;
  }
}

export const getClassificationList = (org_id: string) => {
  return requestClient.get<classificationApi.getClassification>(
    '/device-management/product-category/trees',
    {
      params: {
        org_id,
      },
    },
  );
};

export const createClassification = async (
  data: classificationApi.createClassification,
) => requestClient.post('/device-management/product-category', data);

export const updateClassification = async (
  id: number,
  data: classificationApi.updateClassification,
) => requestClient.put(`/device-management/product-category/${id}`, data);

export const deleteClassification = async (id: number) =>
  requestClient.delete(`/device-management/product-category/`, {
    params: {
      ids: [id],
    },
  });

export const getClassificationFlatList = (org_id: string) =>
  requestClient.get<classificationApi.getClassification>(
    '/device-management/product-category/',
    {
      params: {
        org_id,
      },
    },
  );
