package domain

import "time"

// 订单商品实体
type Good struct {
	// 商品id
	GoodId int64 `json:"goodId"`
	// 预定的货品数量
	GoodNum int `json:"goodNum"`
	// 商品分红支付信息
	GoodDividend *Dividend `json:"goodDividend"`
	// 商品分红支付状态
	GoodDividendStatus int `json:"goodDividendStatus"`
	// 商品名称
	GoodName string `json:"goodName"`
	// 商品单价
	GoodTotalPrice float64 `json:"goodTotalPrice"`
	// 备注
	Remarks string `json:"remarks"`
	// 订单编号
	OrderNo string `json:"orderNo"`
	// 商品详情
	GoodDetail string `json:"goodDetail"`
	// 创建时间
	CreateAt time.Time `json:"createAt"`
	// 更新时间
	UpdateAt time.Time `json:"updateAt"`
	// 删除时间
	DeleteAt time.Time `json:"deleteAt"`
}

type GoodRepository interface {
	Save(good *Good) (*Good, error)
	Remove(good *Good) (*Good, error)
	FindOne(queryOptions map[string]interface{}) (*Good, error)
	Find(queryOptions map[string]interface{}) (int64, []*Good, error)
}

func (good *Good) Identify() interface{} {
	if good.GoodId == 0 {
		return nil
	}
	return good.GoodId
}

func (good *Good) Update(data map[string]interface{}) error {
	if goodId, ok := data["goodId"]; ok {
		good.GoodId = goodId.(int64)
	}
	if goodNum, ok := data["goodNum"]; ok {
		good.GoodNum = goodNum.(int)
	}
	if planBonus, ok := data["planBonus"]; ok {
		good.GoodDividend.PlanBonus = planBonus.(float64)
	}
	if useBonus, ok := data["useBonus"]; ok {
		good.GoodDividend.UseBonus = useBonus.(float64)
	}
	if bonusHas, ok := data["bonusHas"]; ok {
		good.GoodDividend.BonusHas = bonusHas.(float64)
	}
	if bonusNot, ok := data["bonusNot"]; ok {
		good.GoodDividend.BonusNot = bonusNot.(float64)
	}
	if bonusExpense, ok := data["bonusExpense"]; ok {
		good.GoodDividend.BonusExpense = bonusExpense.(float64)
	}
	if bonusStatus, ok := data["bonusStatus"]; ok {
		good.GoodDividend.BonusStatus = bonusStatus.(int)
	}
	if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
		good.GoodDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
	}
	if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
		good.GoodDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
	}
	if salesmanBonus, ok := data["salesmanBonus"]; ok {
		good.GoodDividend.SalesmanBonus = salesmanBonus.(float64)
	}
	if goodDividendStatus, ok := data["goodDividendStatus"]; ok {
		good.GoodDividendStatus = goodDividendStatus.(int)
	}
	if goodName, ok := data["goodName"]; ok {
		good.GoodName = goodName.(string)
	}
	if goodTotalPrice, ok := data["goodTotalPrice"]; ok {
		good.GoodTotalPrice = goodTotalPrice.(float64)
	}
	if remarks, ok := data["remarks"]; ok {
		good.Remarks = remarks.(string)
	}
	if orderNo, ok := data["orderNo"]; ok {
		good.OrderNo = orderNo.(string)
	}
	if goodDetail, ok := data["goodDetail"]; ok {
		good.GoodDetail = goodDetail.(string)
	}
	if createAt, ok := data["createAt"]; ok {
		good.CreateAt = createAt.(time.Time)
	}
	if updateAt, ok := data["updateAt"]; ok {
		good.UpdateAt = updateAt.(time.Time)
	}
	if deleteAt, ok := data["deleteAt"]; ok {
		good.DeleteAt = deleteAt.(time.Time)
	}
	return nil
}