import {
  AddContainerParams,
  BaseListResult,
  BaseResult,
  ContainerListData,
  EditContainerParams,
  GetContainerListParams,
  ScrapContainerLogData,
  ScrapContainerLogParams,
  ScrapContainerParams,
} from '@models';
import {request} from './request';

const BASE_URL = '/container';

/** 获取容器列表 */
export function getContainerList(
  data: GetContainerListParams,
  signal?: AbortSignal,
): BaseListResult<ContainerListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getContainer`,
    data,
    signal,
  });
}

/** 容器导出 */
export function exportContainer(data: GetContainerListParams): any {
  return request({
    method: 'GET',
    url: `${BASE_URL}/export`,
    skipError: true,
    data,
  });
}

/** 新增容器 */
export function addContainer(data: AddContainerParams): BaseResult {
  return request({
    method: 'POST',
    data,
    url: `${BASE_URL}/addContainer`,
  });
}

/** 修改容器 */
export function editContainer(data: EditContainerParams): BaseResult {
  return request({
    method: 'PUT',
    data,
    url: `${BASE_URL}/updateContainer`,
  });
}

/** 删除容器 */
export function deleteContainer(id: string): BaseResult {
  return request({
    method: 'DELETE',
    url: `${BASE_URL}/delCon`,
    data: {id},
  });
}

/** 获取容器详情 */
export function getContainerInfo(
  id: string,
): BaseListResult<ContainerListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getContainer`,
    data: {page: '1', limit: '1', id},
  });
}

/** 容器废弃 */
export function containerScrap(data: ScrapContainerParams): BaseResult {
  return request({
    method: 'DELETE',
    url: `${BASE_URL}/delContainer`,
    data,
    useBody: true,
  });
}

/** 容器废弃日志 */
export function containerScrapLogList(
  data: ScrapContainerLogParams,
  signal?: AbortSignal,
): BaseListResult<ScrapContainerLogData> {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/getScrap`,
    signal,
  });
}

/** 容器废弃日志导出 */
export function containerScrapLogExport(data: ScrapContainerLogParams): any {
  return request({
    method: 'GET',
    data,
    url: `${BASE_URL}/exportScrap`,
    skipError: true,
  });
}
