import { d, put } from './request'
import { g, p } from './request'

export const mallList = async (channel = 'mall', offset = 0, limit = 10) => {
    return await g(`/products/${channel}`, { limit, offset })
}

export const mallDetail = async (id) => {
    return await g(`/products/detail/${id}`)
}



export const login = async (account, pwd, code) => {
    return await p(`/users/login`, { phone: account, password: pwd, verification_code: code })
}

export const register = async (data = {}) => {
    return await p(`/users/register`, data)
}

export const sendCode = async (phone) => {
    return await p('/users/sms-verification-code', { phone })
}

// 创建地址
export const createAddress = async (data = {}) => {
    return await p(`/users/addresses`, data)
}
export const updateAddress = async (id, data = {}) => {
    return await put(`/users/addresses/${id}`, data)
}

export const deleteAddress = async (id) => {
    return await d(`/users/addresses/${id}`)
}


export const getAddress = async (data = {}) => {
    return await g(`/users/addresses`, data)
}
// 获取城市
export const cities = async (pid = 0) => {
    return await g('/cities', { pid })
}

// 下单
export const order = async (channel, data = {}) => {
    return await p(`/orders/${channel}`, data)
}

export const orderList = async (channel, params = {}) => {
    return await g(`/orders/${channel}`, params)
}

// 当前用户信息
export const userDetail = async () => {
    return await g(`/users/detail`)
}

// 我的银行卡
export const cardList = async () => {
    return await g(`/users/bank-cards`)
}

export const createCard = async (data) => {
    return await p(`/users/bank-cards`, data)
}

export const deleteCard = async (id) => {
    return await d(`/users/bank-cards/${id}`)
}


export const pwdManage = async (type, data) => {
    return await put(`/users/profile/password/${type}`, data)
}


export const phoneManage = async (data = {}) => {
    return await put(`/users/profile/phone`, data)
}

export const userLogs = async (type, data = {}) => {
    return await g(`/users/assets/logs/${type}`, data)
}


export const transferAmount = async (data = {}) => {
    return await p(`/users/assets/score-transfer`, data)
}


export const profitToScore = async (amount) => {
    return await p(`/users/assets/profit-to-score`, { amount })
}

export const scoreWithdraw = async (data) => {
    return await p(`/users/assets/score-withdraw`, data)
}

//
export const modifyUser = async (field, value) => {
    return await put(`/users/profile/fields`, { field, value })
}

export const invitedUser = async (data) => {
    return await g(`/users/teams/invited-users`, data)
}

export const invitedAreas = async () => {
    return await g(`/users/teams/invitee-areas`)
}

export const configs = async () => {
    return await g('/config')
}

export const msgList = async (params) => {
    return await g('/news', params)
}

export const msgDetail = async (id) => {
    return await g(`/news/${id}`)
}


export const partners = async (data) => {
    return await p('/partners', data)
}