package supplier

import (
	"context"
	"git.oa00.com/supply-chain/service/client"
	"git.oa00.com/supply-chain/service/lib/bean"
	"github.com/shopspring/decimal"
)

type supplierWalletApply struct {
}

type ArgsSupplierWalletApplyLists struct {
	Search SupplierWalletApplySearch
	Page   bean.Page
}

type SupplierWalletApplySearch struct {
	SupplierName   string          // 供应商名称
	Amount         decimal.Decimal // 变动金额
	ApplyStartDate string          // 申请开始日期
	ApplyEndDate   string          // 申请结束日期
	AuditStatus    uint            // 审核状态
	AuditStartDate string          // 审核开始日期
	AuditEndDate   string          // 审核结束日期
}

type SupplierWalletApplyItem struct {
	Id           uint
	SupplierName string
	Amount       decimal.Decimal
	ApplyUserId  uint
	CreatedAt    int64
	Reason       string
	AuditUserId  uint
	AuditTime    int64
}

type ReplySupplierWalletApplyLists struct {
	Lists []SupplierWalletApplyItem
	Total int64
}

// Lists @Title 申请列表
func (s *supplierWalletApply) Lists(ctx context.Context, args ArgsSupplierWalletApplyLists) (reply ReplySupplierWalletApplyLists, err error) {
	xClient, err := client.GetClient(s)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "Lists", args, &reply)
	return
}

type ReplySupplierWalletApplyInfo struct {
	ApplyId      uint            // 申请表Id
	AuditStatus  uint            // 审核状态
	SupplierName string          // 供应商名称
	Amount       decimal.Decimal // 变动金额
	ApplyUserId  uint            // 申请人
	CreatedAt    int64           // 申请时间
	Proof        string          // 凭证
}

// Info @Title 申请详情
func (s *supplierWalletApply) Info(ctx context.Context, applyId uint) (reply ReplySupplierWalletApplyInfo, err error) {
	xClient, err := client.GetClient(s)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "Info", applyId, &reply)
	return
}

type ArgsSupplierWalletApplyAdopt struct {
	ApplyId     uint
	AuditUserId uint
}

// Adopt @Title 申请通过
func (s *supplierWalletApply) Adopt(ctx context.Context, args ArgsSupplierWalletApplyAdopt) error {
	xClient, err := client.GetClient(s)
	if err != nil {
		return err
	}
	reply := 0
	return xClient.Call(ctx, "Adopt", args, &reply)
}

type ArgsSupplierWalletApplyReject struct {
	ApplyId     uint
	AuditUserId uint
	Reason      string
}

// Reject @Title 申请驳回
func (s *supplierWalletApply) Reject(ctx context.Context, args ArgsSupplierWalletApplyReject) error {
	xClient, err := client.GetClient(s)
	if err != nil {
		return err
	}
	reply := 0
	return xClient.Call(ctx, "Reject", args, &reply)
}

type ArgsSupplierWalletApply struct {
	Type        uint            // 变动类型
	Amount      decimal.Decimal // 变动金额
	Proof       string          // 凭证
	ApplyUserId uint            // 申请人
	SupplierId  uint            // 供应商Id
}

// Apply @Title 变动申请
func (s *supplierWalletApply) Apply(ctx context.Context, args ArgsSupplierWalletApply) error {
	xClient, err := client.GetClient(s)
	if err != nil {
		return err
	}
	reply := 0
	return xClient.Call(ctx, "Apply", args, &reply)
}