package purchase

import (
	"context"
	"git.kumo.work/shama/service/client"
	"github.com/shopspring/decimal"
)

type product struct {
}
type ProductItem struct {
	Id             int64            `json:"id"`
	PurchasePrice  decimal.Decimal  `json:"purchasePrice"`
	PurchaseCount  int64            `json:"purchaseCount"`
	BoxCount       int64            `json:"boxCount"`
	Info           string           `json:"info"`
	Po             string           `json:"po"`
	Mold           int64            `json:"mold"`
	Serial         string           `json:"serial"`
	CustomSerial   string           `json:"customSerial"`
	Name           string           `json:"name"`
	EngName        string           `json:"engName"`
	Description    string           `json:"description"`
	EngDescription string           `json:"engDescription"`
	ImgFilePaths   []string         `json:"imgFilePaths"`
	PurchaseAmount decimal.Decimal  `json:"purchaseAmount"`
	Num            *int64           `json:"num"`
	Volume         *decimal.Decimal `json:"volume"`
	GrossWeight    *decimal.Decimal `json:"grossWeight"`
	NetWeight      *decimal.Decimal `json:"netWeight"`
	MeasureUnit    string           `json:"measureUnit"`
}

// All @TITLE 获取产品
func (p *product) All(ctx context.Context, purchaseId int64) (reply []ProductItem, err error) {
	xClient, err := client.GetClient(p)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "All", purchaseId, &reply)
	return
}

type ArgsProductEdit struct {
	PurchaseId int64 // 采购合同id
	Products   []ProductEdit
}

type ProductEdit struct {
	PurchaseProductId int64           // 采购合同产品id
	Po                string          // 产品po
	Name              string          // 产品名称
	Description       string          // 产品中文描述
	PurchasePrice     decimal.Decimal // 采购单价
	PurchaseCount     int64           // 采购数量
	Info              string          // 备注
	Sort              int64           // 排序
}

// Edit @TITLE 编辑产品
func (p *product) Edit(ctx context.Context, args ArgsProductEdit) (err error) {
	xClient, err := client.GetClient(p)
	if err != nil {
		return
	}
	reply := 0
	err = xClient.Call(ctx, "Edit", args, &reply)
	return
}

type ArgsProductChangeFactory struct {
	FactoryId          int64   // 工厂id
	PurchaseProductIds []int64 // 采购商品id
}

// ChangeFactory @TITLE 更换工厂
func (p *product) ChangeFactory(ctx context.Context, args ArgsProductChangeFactory) (err error) {
	xClient, err := client.GetClient(p)
	if err != nil {
		return
	}
	reply := 0
	err = xClient.Call(ctx, "ChangeFactory", args, &reply)
	return
}

// Delete @TITLE 删除产品
func (p *product) Delete(ctx context.Context, purchaseProductIds []int64) (err error) {
	xClient, err := client.GetClient(p)
	if err != nil {
		return
	}
	reply := 0
	err = xClient.Call(ctx, "Delete", purchaseProductIds, &reply)
	return
}