package logic

import (
	plantModel "sundynix-micro-go/app/plant/model"
	"sundynix-micro-go/app/plant/rpc/plant"
)

func exchangeItemInfo(item plantModel.ExchangeItem) *plant.ExchangeItemInfo {
	cost := item.CostSunlight
	if cost == 0 {
		cost = item.Cost
	}
	imgID := item.ImageID
	if imgID == "" {
		imgID = item.ImgID
	}
	return &plant.ExchangeItemInfo{
		Id: item.ID, Name: item.Name, Desc: item.Desc,
		ImgId: imgID, Cost: cost, Stock: int32(item.Stock), Status: int32(item.Status),
	}
}

func exchangeOrderInfo(o plantModel.ExchangeOrder) *plant.ExchangeOrderInfo {
	completedAt := ""
	if o.CompletedAt != nil {
		completedAt = o.CompletedAt.Format("2006-01-02 15:04:05")
	}
	return &plant.ExchangeOrderInfo{
		Id: o.ID, UserId: o.UserID, ItemId: o.ItemID, ItemName: o.ItemName,
		Cost: o.Cost, Status: int32(o.Status), Address: o.Address,
		CreatedAt: o.CreatedAt.Format("2006-01-02 15:04:05"),
		Quantity:  int32(o.Quantity), ItemType: o.ItemType, RecipientName: o.RecipientName,
		Phone: o.Phone, TrackingNo: o.TrackingNo, Remark: o.Remark, CompletedAt: completedAt,
	}
}
