package domain

import "time"

// 订单商品实体
type Goods struct {
	// 商品id
	GoodsId int64 `json:"goodsId"`
	// 预定的货品数量
	GoodsNum int `json:"goodsNum"`
	// 商品分红支付信息
	GoodsDividend *Dividend `json:"goodsDividend"`
	// 商品分红支付状态
	GoodsDividendStatus int `json:"goodsDividendStatus"`
	// 商品名称
	GoodsName string `json:"goodsName"`
	// 商品单价
	GoodsTotalPrice float64 `json:"goodsTotalPrice"`
	// 备注
	Remarks string `json:"remarks"`
	// 订单编号
	OrderNo     string `json:"orderNo"`
	GoodsDetail string `json:"goodsDetail"`
	// 创建时间
	CreateAt time.Time `json:"createAt"`
	// 更新时间
	UpdateAt time.Time `json:"updateAt"`
	// 删除时间
	DeleteAt time.Time `json:"deleteAt"`
}

type GoodsRepository interface {
	Save(goods *Goods) (*Goods, error)
	Remove(goods *Goods) (*Goods, error)
	FindOne(queryOptions map[string]interface{}) (*Goods, error)
	Find(queryOptions map[string]interface{}) (int64, []*Goods, error)
}

func (goods *Goods) Identify() interface{} {
	if goods.GoodsId == 0 {
		return nil
	}
	return goods.GoodsId
}

func (goods *Goods) Update(data map[string]interface{}) error {
	if goodsId, ok := data["goodsId"]; ok {
		goods.GoodsId = goodsId.(int64)
	}
	if goodsNum, ok := data["goodsNum"]; ok {
		goods.GoodsNum = goodsNum.(int)
	}
	if planBonus, ok := data["planBonus"]; ok {
		goods.GoodsDividend.PlanBonus = planBonus.(float64)
	}
	if useBonus, ok := data["useBonus"]; ok {
		goods.GoodsDividend.UseBonus = useBonus.(float64)
	}
	if bonusHas, ok := data["bonusHas"]; ok {
		goods.GoodsDividend.BonusHas = bonusHas.(float64)
	}
	if bonusNot, ok := data["bonusNot"]; ok {
		goods.GoodsDividend.BonusNot = bonusNot.(float64)
	}
	if bonusExpense, ok := data["bonusExpense"]; ok {
		goods.GoodsDividend.BonusExpense = bonusExpense.(float64)
	}
	if bonusStatus, ok := data["bonusStatus"]; ok {
		goods.GoodsDividend.BonusStatus = bonusStatus.(int)
	}
	if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
		goods.GoodsDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
	}
	if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
		goods.GoodsDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
	}
	if salesmanBonus, ok := data["salesmanBonus"]; ok {
		goods.GoodsDividend.SalesmanBonus = salesmanBonus.(float64)
	}
	if goodsDividendStatus, ok := data["goodsDividendStatus"]; ok {
		goods.GoodsDividendStatus = goodsDividendStatus.(int)
	}
	if goodsName, ok := data["goodsName"]; ok {
		goods.GoodsName = goodsName.(string)
	}
	if goodsTotalPrice, ok := data["goodsTotalPrice"]; ok {
		goods.GoodsTotalPrice = goodsTotalPrice.(float64)
	}
	if remarks, ok := data["remarks"]; ok {
		goods.Remarks = remarks.(string)
	}
	if orderNo, ok := data["orderNo"]; ok {
		goods.OrderNo = orderNo.(string)
	}
	if goodsDetail, ok := data["goodsDetail"]; ok {
		goods.GoodsDetail = goodsDetail.(string)
	}
	if createAt, ok := data["createAt"]; ok {
		goods.CreateAt = createAt.(time.Time)
	}
	if updateAt, ok := data["updateAt"]; ok {
		goods.UpdateAt = updateAt.(time.Time)
	}
	if deleteAt, ok := data["deleteAt"]; ok {
		goods.DeleteAt = deleteAt.(time.Time)
	}
	return nil
}