import { v4 } from 'uuid'
import { useLoginStore } from '@/stores'
import http from '@/services/http'
import tradeServer from '@/services/socket/trade'

const loginStore = useLoginStore()
const { userId } = loginStore.$toRefs()

/**
 * 获取保税商品表
 */
export function queryGZBSCGoods() {
    return http.commonRequest<Ermcp.GZBSCGoodsRsp[]>({
        url: '/Guangzuan/GetGZBSCGoods',
    })
}

/**
 * 保税仓出入库申请表查询
 */
export function queryGzbscinOutOrder(params: Ermcp.GzbscinOutOrderReq) {
    return http.commonRequest<Ermcp.GzbscinOutOrderRsp[]>({
        url: '/Guangzuan/QueryGzbscinOutOrder',
        params,
    })
}

/**
 * 保税仓出库申请明细附表查询
 */
export function queryBScinOutOrderDetail(params: Ermcp.BScinOutOrderDetailReq) {
    return http.commonRequest<Ermcp.BScinOutOrderDetailRsp[]>({
        url: '/Guangzuan/QueryBScinOutOrderDetail',
        params,
    })
}

/**
 * 保税商品报关头寸表查询
 */
export function queryGzbscPosition(params: Ermcp.GzbscPositionReq) {
    return http.commonRequest<Ermcp.GzbscPositionRsp[]>({
        url: '/Guangzuan/QueryGzbscPosition',
        params,
    })
}

/**
 * 保税仓出库申请明细附表查询
 */
export function queryBScOutOrderDetailatt(params: Ermcp.BScOutOrderDetailattReq) {
    return http.commonRequest<Ermcp.BScOutOrderDetailattRsp[]>({
        url: '/Guangzuan/QueryBScOutOrderDetailatt',
        params,
    })
}

/**
 * 保税仓用户月付款通知书表查询（计费管理）
 */
export function queryGzbscusermonthpay(params: Ermcp.GzbscusermonthpayReq) {
    return http.commonRequest<Ermcp.GzbscusermonthpayRsp[]>({
        url: '/Guangzuan/QueryGzbscusermonthpay',
        params,
    })
}

/**
 * 保税仓月电费登记表查询
 */
export function queryGzbscuserpowerfee(params: Ermcp.GzbscuserpowerfeeReq) {
    return http.commonRequest<Ermcp.GzbscuserpowerfeeRsp[]>({
        url: '/Guangzuan/QueryGzbscuserpowerfee',
        params,
    })
}

/**
 * 保税仓本月进口明细/本月出境明细/本月转厂明细查询
 */
export function queryBscinoutorder(params: Ermcp.BscinoutorderReq) {
    return http.commonRequest<Ermcp.BscinoutorderRsp[]>({
        url: '/Guangzuan/QueryBscinoutorder',
        params,
    })
}

/**
 * 保税仓结算单表查询
 */
export function queryGzbscreckonorder(params: Ermcp.GzbscreckonorderReq) {
    return http.commonRequest<Ermcp.GzbscreckonorderRsp[]>({
        url: '/Guangzuan/QueryGzbscreckonorder',
        params: {
            userid: userId.value,
            ...params
        },
    })
}

/**
 * 保税仓进出仓申请
 */
export function bscInAndOutWareHouseApply(params: Proto.BSCInAndOutWareHouseApplyReq) {
    return tradeServer.sendMessage<Proto.BSCInAndOutWareHouseApplyRsp>({
        params,
        reqName: 'BSCInAndOutWareHouseApplyReq',
        rspName: 'BSCInAndOutWareHouseApplyRsp',
        marketId: 66201
    })
}

/**
 * 保税仓上传文件
 */
export function bscUploadFile(params: Proto.BSCUploadFileReq) {
    return tradeServer.sendMessage<Proto.BSCUploadFileRsp>({
        params,
        reqName: 'BSCUploadFileReq',
        rspName: 'BSCUploadFileRsp',
        marketId: 66201
    })
}

/**
 * 保税仓确认支付
 */
export function bscConfirmPay(params: Proto.BSCConfirmPayReq) {
    return tradeServer.sendMessage<Proto.BSCConfirmPayRsp>({
        params,
        reqName: 'BSCConfirmPayReq',
        rspName: 'BSCConfirmPayRsp',
        marketId: 66201
    })
}

/**
 * WMS结算单支付
 */
export function bsWMSReckonPay(params: Partial<Proto.BSWMSReckonPayReq>) {
    return tradeServer.sendMessage<Proto.BSWMSReckonPayRsp>({
        params: {
            UserID: userId.value,
            ClientSerialNo: v4(),
            ...params
        },
        reqName: 'BSWMSReckonPayReq',
        rspName: 'BSWMSReckonPayRsp',
        marketId: 66201
    })
}