package gomei

import (
	"fmt"
	gomei "git.rosy.net.cn/baseapi/platformapi/gome_live_show"
	"git.rosy.net.cn/baseapi/platformapi/jdshopapi"
	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/business/jxutils"
	"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
	"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
	"git.rosy.net.cn/jx-callback/business/model"
	"git.rosy.net.cn/jx-callback/business/model/dao"
	"git.rosy.net.cn/jx-callback/globals/api"
)

func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorStoreName string) (storeDetail *dao.StoreDetail, err error) {
	if vendorStoreName != "" {
		result2, _ := api.GuoMeiApi.QueryStoreList(&gomei.GetStoreListReq{
			StoreName: vendorStoreName,
		})
		if len(result2.Data.Records) != model.YES {
			return storeDetail, fmt.Errorf("国美未查询到该平台门店，平台门店ID：[%v]", vendorStoreID)
		}
		storeDetail = &dao.StoreDetail{}
		storeDetail.Name = result2.Data.Records[0].StoreName
		storeDetail.Lat = jxutils.StandardCoordinate2Int(utils.Str2Float64("0.000"))
		storeDetail.Lng = jxutils.StandardCoordinate2Int(utils.Str2Float64("0.000"))
	}
	return storeDetail, err
}

// stoerIDs为nil表示所有
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
	return nil
}

func (p *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName string, params map[string]interface{}, storeDetail *dao.StoreDetail) (vendorStoreID string, err error) {
	return "", err
}

func (p *PurchaseHandler) DeleteStore(db *dao.DaoDB, storeID int, userName string) (err error) {
	return err
}

func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
	return hint, err
}

func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string) (storeStatus int, err error) {
	return storeStatus, err
}

func (p *PurchaseHandler) EnableAutoAcceptOrder(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, isSetEnable bool) (err error) {
	return err
}

func (c *PurchaseHandler) UpdateStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, status int) (err error) {
	err = api.JdShopAPI.UpdateStatus(utils.Str2Int(vendorStoreID), jxStatus2JdsStatus(status))
	return err
}

func (c *PurchaseHandler) UpdateStoreOpTime(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, opTimeList []int16) (err error) {
	return err
}

func (c *PurchaseHandler) GetAllStoresVendorID(ctx *jxcontext.Context, vendorOrgCode string) (vendorStoreIDs []string, err error) {
	return vendorStoreIDs, err
}

func (c *PurchaseHandler) UpdateStoreCustomID(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string, storeID int64) (err error) {
	return err
}

func jxStatus2JdsStatus(status int) (result int) {
	if status == model.StoreStatusOpened {
		result = jdshopapi.JdsStoreStatusOnline
	} else if status == model.StoreStatusHaveRest || status == model.StoreStatusClosed {
		result = jdshopapi.JdsStoreStatusRest
	} else {
		result = jdshopapi.JdsStoreStatusDisable
	}
	return result
}

func (c *PurchaseHandler) UpdateStoreLineStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, lineStatus int) (err error) {
	return err
}
