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

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

/**
 * 查询收货地址信息
 */
export function queryUserReceiveInfo(params?: Ermcp.UserReceiveInfoReq) {
    return http.commonRequest<Ermcp.UserReceiveInfoRsp[]>({
        url: '/Qhj/QueryUserReceiveInfo',
        params: {
            userid: userId.value,
            ...params
        },
    })
}

/**
 * 查询发票信息
 */
export function queryWrUserReceiptInfo(params?: Ermcp.WrUserReceiptInfoReq) {
    return http.commonRequest<Ermcp.WrUserReceiptInfoRsp[]>({
        url: '/WrTrade2/QueryWrUserReceiptInfo',
        params: {
            userid: userId.value,
            ...params
        },
    })
}

/**
 * 新增修改收货地址
 */
export function userReceiveInfo(params: Proto.UserReceiveInfoReq) {
    return tradeServer.sendMessage<Proto.UserReceiveInfoRsp>({
        params,
        reqName: 'UserReceiveInfoReq',
        rspName: 'UserReceiveInfoRsp'
    })
}

/**
 * 删除收货地址
 */
export function delUserReceiveInfo(params: Proto.DelUserReceiveInfoReq) {
    return tradeServer.sendMessage<Proto.DelUserReceiveInfoRsp>({
        params,
        reqName: 'DelUserReceiveInfoReq',
        rspName: 'DelUserReceiveInfoRsp'
    })
}

/**
 * 设置默认收货地址
 */
export function userReceiveIsDefault(params: Proto.UserReceiveIsDefaultReq) {
    return tradeServer.sendMessage<Proto.UserReceiveIsDefaultRsp>({
        params,
        reqName: 'UserReceiveIsDefaultReq',
        rspName: 'UserReceiveIsDefaultRsp'
    })
}

/**
 * 新增修改用户发票信息
 */
export function userReceiptInfo(params: Proto.UserReceiptInfoReq) {
    return tradeServer.sendMessage<Proto.UserReceiptInfoRsp>({
        params,
        reqName: 'UserReceiptInfoReq',
        rspName: 'UserReceiptInfoRsp'
    })
}

/**
 * 删除用户发票信息
 */
export function delUserReceiptInfo(params: Proto.DelUserReceiptInfoReq) {
    return tradeServer.sendMessage<Proto.DelUserReceiptInfoRsp>({
        params,
        reqName: 'DelUserReceiptInfoReq',
        rspName: 'DelUserReceiptInfoRsp'
    })
}