import { request } from '@/http/axios'
import type { CabinetDetailResponse, RentingCabinetDetailDTO } from './type'
import { OpenCabinetApiData } from '../shop/type'

/** 获取智能柜详情接口 */
export function getCabinetDetailApi(shopId: number) {
  return request<CabinetDetailResponse>({
    url: 'cabinet/detail',
    method: 'get',
    params: {
      shopId
    }
  })
}

/** 获取出租中的智能柜详情接口 */
export function getRentingCabinetDetailApi(shopId: number) {
  return request<ApiResponseData<RentingCabinetDetailDTO[]>>({
    url: 'cabinet/detail/renting',
    method: 'get',
    params: {
      shopId
    }
  })
}

/** 获取自己租用中的智能柜详情接口 */
export function getUserRentedCabinetListApi(corpid:string, ab98UserId: number) {
  return request<ApiResponseData<RentingCabinetDetailDTO[]>>({
    url: 'cabinet/detail/user',
    method: 'get',
    params: {
      corpid,
      ab98UserId
    }
  })
}

export function openCabinet(cabinetId: number, pinNo: number, data: OpenCabinetApiData) {
  return request<ApiResponseData<void>>({
    url: `cabinet/openCabinet/${cabinetId}/${pinNo}`,
    method: 'post',
    data
  })
}

export const configureGoodsCellsStock = (cellId: number, goodsId: number, stock: number) => {
  return request<ApiResponseData<void>>({
    url: `/cabinet/configureGoodsCellsStock/${cellId}/${goodsId}/${stock}`,
    method: 'put'
  });
};

export const changeGoodsCellsStock = (cellId: number, stock: number) => {
  return request<ApiResponseData<void>>({
    url: `/cabinet/changeGoodsCellsStock/${cellId}/${stock}`,
    method: 'put'
  });
};

export const clearGoodsCells = (cellId: number) => {
  return request<ApiResponseData<void>>({ 
    url: `/cabinet/clearGoodsCells/${cellId}`,
    method: 'put'
  });
};

