package accounting

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

type cost struct {
}

type CostItem struct {
	Id               int64           `json:"id"`
	FactoryId        int64           `json:"factoryId"`
	FactoryName      string          `json:"factoryName"`
	FactoryShortName string          `json:"factoryShortName"`
	Name             string          `json:"name"`
	Amount           decimal.Decimal `json:"amount"`
	Remarks          string          `json:"remarks"`
	CreatedAt        *time.Time      `json:"createdAt"`
	UpdatedAt        *time.Time      `json:"updatedAt"`
}

// All @TITLE 获取费用
func (c *cost) All(ctx context.Context, accountingId int64) (reply []CostItem, err error) {
	xClient, err := client.GetClient(c)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "All", accountingId, &reply)
	return
}

type ArgsCostAdd struct {
	AccountingId int64 // 做账合同ID
	CostAdd
}

type CostAdd struct {
	FactoryId int64           // 工厂id
	Name      string          // 费用名
	Amount    decimal.Decimal // 金额
	Remarks   string          // 备注信息
}

// Add @TITLE 添加费用
func (c *cost) Add(ctx context.Context, args ArgsCostAdd) (err error) {
	xClient, err := client.GetClient(c)
	if err != nil {
		return
	}
	reply := 0
	return xClient.Call(ctx, "Add", args, &reply)
}

type ArgsCostEdit struct {
	CostId int64 // 费用ID
	CostAdd
}

// Edit @TITLE 编辑费用
func (c *cost) Edit(ctx context.Context, args ArgsCostEdit) (err error) {
	xClient, err := client.GetClient(c)
	if err != nil {
		return
	}
	reply := 0
	return xClient.Call(ctx, "Edit", args, &reply)
}

// Delete @TITLE 删除费用
func (c *cost) Delete(ctx context.Context, costIds []int64) (err error) {
	xClient, err := client.GetClient(c)
	if err != nil {
		return
	}
	reply := 0
	return xClient.Call(ctx, "Delete", costIds, &reply)
}