import request from '../utils/request';
import { Result, ResultList, _Pager_Params } from './types';

export interface ButtonFields {
  searchValue: string;
  createBy: string;
  createTime: string;
  updateBy: string;
  updateTime: string;
  remark: string;
  params: Record<string, any>;
  buttonId: string;
  menuName: string;
  menuPath: string;
  buttonName: string;
  perms: string;
  status: string;
}

interface GetListProps extends _Pager_Params, ButtonFields {}

export const getListApi = async (params?: Partial<GetListProps>) => {
  return request<ResultList<ButtonFields[]>>({
    url: '/button/list',
    method: 'get',
    params,
  });
};

export const delApi = async (deleteKeys: ButtonFields['buttonId'][]) => {
  const deleteKeysString = deleteKeys.join(',');
  return await request<Result>({
    url: `/button/delete/${deleteKeysString || ''}`,
    method: 'get',
  });
};

export const updateApi = async (data: Partial<ButtonFields>) => {
  return await request<Result>({
    url: '/button/edit',
    method: 'post',
    data,
  });
};

export const addApi = async (data: Partial<Omit<ButtonFields, 'buttonId'>>) => {
  return await request<Result>({
    url: '/button',
    method: 'post',
    data,
  });
};
