package mtwmapi

import "git.rosy.net.cn/baseapi/utils"

const (
	PoiOpenLevelNormal   = 1 // 为可配送
	PoiOpenLevelHaveRest = 3 // 为休息中

	PoiStatusOffline   = 0 // 为下线
	PoiStatusOnline    = 1 // 为上线
	PoiStatusUploading = 2 // 为上单中
	PoiStatusChecking  = 3 // 为审核通过可上线
)

const (
	PeiSongTypeSelf             = "0000"     // 商家自配
	PeiSongTypeQuHuo            = "0002"     // 趣活
	PeiSongTypeDada             = "0016"     // 达达
	PeiSongTypeE                = "0033"     // E代送
	PeiSongTypeMTZSJM           = "1001"     // 美团专送-加盟
	PeiSongTypeMTZSZJ           = "1002"     // 美团专送-自建
	PeiSongTypeMTZSPT           = "1003"     // 美团跑腿（原众包）
	PeiSongTypeMTZSDL           = "1004"     // 美团专送-城市代理
	PeiSongTypeJiaoMa           = "2001"     // 角马
	PeiSongTypeKuaiDi           = "2002"     // 快送
	PeiSongTypeWholeCity        = "2010"     // 全城送
	PeiSongTypeMixed            = "3001"     // 混合送（即美团专送+快送）
	PeiSongTypeQiKe             = "4015"     // 企客远距离配送
	PeiSongTypeMixedExpressQiKe = "30012002" // 混合快送
	PeiSongTypeFranchise        = "30011001" // 混合加盟送
	PeiSongTypeMixedSelf        = "30011002" // 混合自建
	PeiSongTypeNewQuik          = "1007"     // 新快送
)

func (a *API) ShippingSave(poiCode string, area string, minPrice, shippingFee float32) (err error) {
	_, err = a.AccessAPI("shipping/save", false, map[string]interface{}{
		KeyAppPoiCode:       poiCode,
		"app_shipping_code": 1,
		"type":              1,
		"area":              area,
		"min_price":         minPrice,
		"shipping_fee":      shippingFee,
	})
	return err
}

func (a *API) ShippingList(poiCode string) (shippingList []map[string]interface{}, err error) {
	result, err := a.AccessAPI("shipping/list", true, map[string]interface{}{
		KeyAppPoiCode: poiCode,
	})
	if err == nil {
		return utils.Slice2MapSlice(result.([]interface{})), nil
	}
	return nil, err
}

func (a *API) ShippingFetch(poiCode string) (shippingList []map[string]interface{}, err error) {
	result, err := a.AccessAPI("shipping/fetch", true, map[string]interface{}{
		KeyAppPoiCode: poiCode,
	})
	if err == nil {
		return utils.Slice2MapSlice(result.([]interface{})), nil
	}
	return nil, err
}
