package controllers

import (
	"errors"
	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/business/bidding"
	"git.rosy.net.cn/jx-callback/business/model"
	"git.rosy.net.cn/jx-callback/globals/api"
	"github.com/astaxie/beego/server/web"
)

type BiddingController struct {
	web.Controller
}

// @Title 获取招标信息
// @Description 获取招标信息
// @Param	token			header		string	false	"认证token"
// @Param	title			query		string	false	"标题"
// @Param	city			query		string	false	"标题"
// @Param   startTime       query		string	false	"开始时间"
// @Param   endTime      	query		string	false	"结束时间"
// @Param   pageSize      	query		int		false	"页数"
// @Param   pageNumber      query		int		false	"页码"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetBiddingMsg [get]
func (c *BiddingController) GetBiddingMsg() {
	c.callGetBiddingMsg(func(params *tBindGetBiddingMsgParams) (retVal interface{}, errCode string, err error) {
		retVal, err = bidding.GetBiddingMsg(params.Ctx, params.MapData)
		return retVal, "", err
	})
}

// GetRefundOrderList 获取退货账单
// @Title 获取招标信息
// @Description 获取招标信息
// @Param	token			header		string	true	"认证token"
// @Param	brandId			query		int		true	"品牌"
// @Param	start			query		string	true	"开始时间"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetRefundOrderList [get]
func (c *BiddingController) GetRefundOrderList() {
	c.callGetRefundOrderList(func(params *tBindGetRefundOrderListParams) (interface{}, string, error) {
		data, err := bidding.GetBrandPayOrder(params.BrandId, params.Start)
		return data, "", err
	})
}

// GetStoreBindStatus 查询门店是否绑定成功,成功之后创建本地门店
// 查询门店是否绑定成功,成功之后创建本地门店
// @Title 查询门店是否绑定成功,成功之后创建本地门店
// @Description 查询门店是否绑定成功,成功之后创建本地门店
// @Param	token			header		string	true	"认证token"
// @Param	platformId		query		string	false	"授权成功平台id"
// @Param	platformType	query		int		false	"授权平台id"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetStoreBindStatus [get]
func (c *BiddingController) GetStoreBindStatus() {
	c.callGetStoreBindStatus(func(params *tBindGetStoreBindStatusParams) (interface{}, string, error) {
		switch params.PlatformType {
		case model.VendorIDMTWM:
			data, err := api.Mtwm2API.GetBoundList(params.PlatformId)
			if err != nil {
				return nil, "", err
			}
			for _, v := range data {
				if v.AppID == utils.Str2Int(params.PlatformId) {
					return data, "", nil
				}
			}
			return nil, "", errors.New("未查询到绑定数据,请检查美团门店id是否正确")
		case model.VendorIDEBAI:

		case model.VendorIDJD:
		case model.VendorIDTT:

		}
		return nil, "", nil
	})
}

// NeedDeleteGetStoreBindStatus 查询门店是否绑定成功,成功之后创建本地门店
// 查询门店是否绑定成功,成功之后创建本地门店
// @Title 查询门店是否绑定成功,成功之后创建本地门店
// @Description 查询门店是否绑定成功,成功之后创建本地门店
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /NeedDeleteGetStoreBindStatus [get]
func (c *BiddingController) NeedDeleteGetStoreBindStatus() {
	c.callNeedDeleteGetStoreBindStatus(func(params *tBindNeedDeleteGetStoreBindStatusParams) (interface{}, string, error) {
		dd := bidding.QueryNeedDeleteSku()
		return dd, "", nil
	})
}

// UpdateTiktokOrderPhoneAddress 更新抖音电话归属地
// @Title 更新抖音电话归属地
// @Description 更新抖音电话归属地
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /UpdateTiktokOrderPhoneAddress [get]
func (c *BiddingController) UpdateTiktokOrderPhoneAddress() {
	c.callUpdateTiktokOrderPhoneAddress(func(params *tBindUpdateTiktokOrderPhoneAddressParams) (interface{}, string, error) {
		err := bidding.UpdateTiktokOrderPhoneAddress()
		return nil, "", err
	})
}
