package jx

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

	"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/partner"
	"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
	"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/phpjx"
)

func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) {
	return order
}

func (c *PurchaseHandler) GetOrder(vendorOrgCode, orderID, vendorStoreID string) (order *model.GoodsOrder, err error) {
	order, err = partner.CurOrderManager.LoadOrder(orderID, model.VendorIDJX)
	return order, err
}

func (p *PurchaseHandler) GetOrderStatus(vendorOrgCode, vendorOrderID string) (status int, err error) {
	order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, model.VendorIDJX)
	if err == nil {
		status = order.Status
	}
	return status, err
}

func (c *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error) {
	var status int
	if isAcceptIt {
		status = model.OrderStatusAccepted
	} else {
		status = model.OrderStatusCanceled
	}
	if model.IsOrderJXTemp(order) {
		err = phpjx.NotifyOrderStatusChanged(order, status)
	} else {
		err = localjx.AcceptOrRefuseOrder(order, isAcceptIt, userName)
	}
	return err
}

func (c *PurchaseHandler) PickupGoods(order *model.GoodsOrder, isSelfDelivery bool, userName string) (err error) {
	if model.IsOrderJXTemp(order) {
		err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusFinishedPickup)
	} else {
		err = localjx.PickupGoods(order, isSelfDelivery, userName)
	}
	return err
}

func (p *PurchaseHandler) AcceptOrRefuseFailedGetOrder(ctx *jxcontext.Context, order *model.GoodsOrder, isAcceptIt bool) (err error) {
	return err
}

func (p *PurchaseHandler) CallCourier(ctx *jxcontext.Context, order *model.GoodsOrder) (err error) { // 拣货失败后再次招唤平台配送
	return err
}

func (p *PurchaseHandler) ConfirmReceiveGoods(ctx *jxcontext.Context, order *model.GoodsOrder) (err error) { // 投递失败后确认收到退货
	return err
}

func (c *PurchaseHandler) Swtich2SelfDeliver(order *model.GoodsOrder, userName string) (err error) {
	return err
}

func (c *PurchaseHandler) Swtich2SelfDelivered(order *model.GoodsOrder, userName string) (err error) {
	return err
}

func (c *PurchaseHandler) SelfDeliverDelivering(order *model.GoodsOrder, userName string) (err error) {
	if model.IsOrderJXTemp(order) {
		err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusDelivering)
	} else {
		err = localjx.SelfDeliverDelivering(order, userName)
	}
	return err
}

func (c *PurchaseHandler) SelfDeliverDelivered(order *model.GoodsOrder, userName string) (err error) {
	if model.IsOrderJXTemp(order) {
		err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusFinished)
	} else {
		err = localjx.SelfDeliverDelivered(order, userName)
	}
	return err
}

func (c *PurchaseHandler) GetOrderRealMobile(ctx *jxcontext.Context, order *model.GoodsOrder) (mobile string, err error) {
	return mobile, err
}

func (c *PurchaseHandler) AgreeOrRefuseCancel(ctx *jxcontext.Context, order *model.GoodsOrder, isAgree bool, reason string, refundParam interface{}) (err error) {
	if model.IsOrderJXTemp(order) {
	} else {
		err = localjx.AgreeOrRefuseCancel(ctx, order, isAgree, reason, nil)
	}
	return err
}

func (c *PurchaseHandler) CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) (err error) {
	if model.IsOrderJXTemp(order) {
		err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusCanceled)
	} else {
		err = localjx.CancelOrder(ctx, order, reason)
	}
	return err
}

func (c *PurchaseHandler) AdjustOrder(ctx *jxcontext.Context, order *model.GoodsOrder, removedSkuList []*model.OrderSku, reason string) (err error) {
	if model.IsOrderJXTemp(order) {
	} else {
		err = localjx.AdjustOrder(ctx, order, removedSkuList, reason)
	}
	return err
}

func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, queryDate time.Time, vendorStoreID string) (vendorOrderIDs []string, err error) {
	return vendorOrderIDs, err
}

func (c *PurchaseHandler) ConfirmSelfTake(ctx *jxcontext.Context, order *model.GoodsOrder, selfTakeCode string) (err error) {
	// order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, model.VendorIDJX)
	// if err == nil {
	// 	if model.IsOrderJXTemp(order) {
	// 		err = phpjx.NotifyOrderStatusChanged(order, model.OrderStatusFinished)
	// 	}
	// }
	return err
}

func (c *PurchaseHandler) GetSelfTakeCode(ctx *jxcontext.Context, order *model.GoodsOrder) (selfTakeCode string, err error) {
	return selfTakeCode, err
}

func (c *PurchaseHandler) ComplaintRider(vendorOrderId string, resonID int, resonContent string) (err error) {
	return err
}

// 转自配送时取消非专送混合送门店取消理由
func (c *PurchaseHandler) GetCancelDeliveryReason(order *model.GoodsOrder) (string, error) {
	return "", nil
}

// 取消美团外卖理由转使用三方配送
func (c *PurchaseHandler) CancelLogisticsByWmOrderId(order *model.GoodsOrder, reasonCode, detailContent, appPoiCode, orderId string) error {
	return nil
}

// 获取订单配送状态
func (c *PurchaseHandler) OrderLogisticsStatus(orderId string) (*utils.RiderInfo, error) {
	return nil, nil
}

// GetOrderSettleAccounts 获取订单结算信息
func (c *PurchaseHandler) GetOrderSettleAccounts(order *model.GoodsOrder) (int64, error) {
	return 0, nil
}

// GetPlatformLogisticsFee 获取自配送订单的配送费
func (c *PurchaseHandler) GetPlatformLogisticsFee(order *model.GoodsOrder) (int64, error) {
	return 0, nil
}

// ApplyCompensationOrder 订单索赔
func (c *PurchaseHandler) ApplyCompensationOrder(order *model.GoodsOrder) (string, error) {
	return "", nil
}

// UploadInvoice 回复用户发票申请
func (c *PurchaseHandler) UploadInvoice(param *model.InvoiceMsg) ([]string, []string, error) {
	return nil, nil, nil
}

// UploadPickingImg  上传拣货图片
func (c *PurchaseHandler) UploadPickingImg(order *model.GoodsOrder, imgList interface{}) error {
	return nil
}
