package workflow

import (
	"context"
	"git.kumo.work/shama/service/client"
	"git.kumo.work/shama/service/lib/bean"
	"time"
)

type node struct {
}

type ArgsNodeCountSearch struct {
	StaffIds []int64 // 员工筛选
	Status   []int64 // 状态筛选
}

type NodeCountItem struct {
	BusinessType string `json:"businessType"`
	Count        int64  `json:"count"`
}

// Count @TITLE 节点统计
func (n *node) Count(ctx context.Context, args ArgsNodeCountSearch) (reply []NodeCountItem, err error) {
	xClient, err := client.GetClient(n)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "Count", args, &reply)
	return
}

type ArgsNodeList struct {
	Page   bean.Page
	Search NodeSearch
}
type NodeSearch struct {
	StaffIds      []int64  // 员工筛选
	Status        []int64  // 状态筛选
	BusinessType  string   // 业务类型
	BusinessTypes []string // 业务类型
}
type ReplyNodeList struct {
	List  []NodeItem `json:"list"`
	Total int64      `json:"total"`
}
type NodeItem struct {
	Id             int64      `json:"id"`
	BusinessId     int64      `json:"businessId"`
	BusinessName   string     `json:"businessName"`
	BusinessType   string     `json:"businessType"`
	Status         int64      `json:"status"`
	Title          string     `json:"title"`
	Content        string     `json:"content"`
	ReviewComments string     `json:"reviewComments"` // 审批意见
	CreatedStaffId int64      `json:"createdStaffId"` // 创建人
	CreatedAt      *time.Time `json:"createdAt"`
	UpdatedAt      *time.Time `json:"updatedAt"` // 更新时间
	Data           string     `json:"data"`
}

// List @TITLE 节点列表
func (n *node) List(ctx context.Context, args ArgsNodeList) (reply ReplyNodeList, err error) {
	xClient, err := client.GetClient(n)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "List", args, &reply)
	return
}

type ArgsNodeAdopt struct {
	StaffId int64 // 审核人
	NodeId  int64 // 节点id
}

// Adopt @TITLE 审核通过
func (n *node) Adopt(ctx context.Context, args ArgsNodeAdopt) (err error) {
	xClient, err := client.GetClient(n)
	if err != nil {
		return
	}
	reply := 0
	err = xClient.Call(ctx, "Adopt", args, &reply)
	return
}

type ArgsNodeReject struct {
	StaffId int64  // 审核人
	NodeId  int64  // 节点id
	Reason  string // 审核结果
}

// Reject @TITLE 审核驳回
func (n *node) Reject(ctx context.Context, args ArgsNodeReject) (err error) {
	xClient, err := client.GetClient(n)
	if err != nil {
		return
	}
	reply := 0
	err = xClient.Call(ctx, "Reject", args, &reply)
	return
}