package controllers

import (
	"git.rosy.net.cn/jx-callback/business/enterprise"
	"git.rosy.net.cn/jx-callback/business/enterprise_session"
	"git.rosy.net.cn/jx-callback/business/jxutils"
	"github.com/astaxie/beego/server/web"
)

type SessionController struct {
	web.Controller
}

// 创建门店老板的会话群
// @Title 创建门店老板的会话群
// @Description 创建门店老板的会话群
// @Param	token			header		string	true	"认证token"
// @Param	storeId			formData	int	    true	"门店id"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateBossSession [post]
func (c *SessionController) CreateBossSession() {
	c.callCreateBossSession(func(params *tSessionCreateBossSessionParams) (interface{}, string, error) {
		session := enterprise_session.CreateSession{}
		result, err := session.CreateBossToStaffAndCreateSession(params.Token, params.StoreId)
		return result, "", err
	})

}

// 获取企业微信token
// @Title 创建门店老板的会话群
// @Description 创建门店老板的会话群
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetEnterpriseToken [Get]
func (c *SessionController) GetEnterpriseToken() {
	c.callGetEnterpriseToken(func(params *tSessionGetEnterpriseTokenParams) (interface{}, string, error) {
		token, mintoken := enterprise_session.GetEnterpriseTokenInfo()

		return map[string]string{"minToken": mintoken, "enterpriseToken": token}, "", nil
	})
}

// @Title 校验平台商品和京西系统商品的差异
// @Description 校验平台商品和京西系统商品的差异
// @Param	token			header		string	true	"认证token"
// @Param	storeId			formData	int		true	"门店ID列表"
// @Param	vendorIDs		formData	string	true	"厂商ID列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CheckVendorSkuDiffer [post]
func (c *SessionController) CheckVendorSkuDiffer() {
	c.callCheckVendorSkuDiffer(func(params *tSessionCheckVendorSkuDifferParams) (retVal interface{}, errCode string, err error) {
		var vendorIDs []int
		if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs); err != nil {
			return retVal, "", err
		}

		errStr, err := enterprise.CompareJxVendorSku(params.StoreId, vendorIDs)
		return errStr, "", err
	})
}
