package contracts

import (
	"net/http"

	"git.fsdpf.net/go/db"
)

type UserApprovalExecute int

// 审批状态
type UserApprovalStatus int

// 审批节点类型
type UserApprovalFlowType int

const (
	// 驳回
	UserApprovalExecute_Reject UserApprovalExecute = iota
	// 通过
	UserApprovalExecute_Resolve
)

const (
	// 待审批
	UserApprovalStatus_Accept UserApprovalStatus = iota
	// 审批中
	UserApprovalStatus_Pending
	// 通过
	UserApprovalStatus_Resolve
	// 驳回
	UserApprovalStatus_Reject
	// 取消审批
	UserApprovalStatus_Cancel
)

const (
	// 角色节点
	UserApprovalFlowType_Role UserApprovalFlowType = iota + 1
	// 自动节点
	UserApprovalFlowType_Condition
	// 开始节点
	UserApprovalFlowType_Begin
	// 通过节点
	UserApprovalFlowType_Reject
	// 驳回节点
	UserApprovalFlowType_Resolve
)

type UserApproval interface {
	// 审批流名称
	Name() string
	// 发起审批请求
	RequestApproval(Route, *http.Request) any
	// 判断发起审批请求权限
	HasUserRoles(User) bool
	// 获取审批列表标记字段值
	Execute(id int64, status UserApprovalExecute, r *http.Request, tx *db.Transaction) (current, next UserApprovalFlow, err error)
}

type UserApprovalFlow interface {
	// 节点名称
	Name() string
	// 节点UUID
	Uuid() string
	// 节点类型
	Type() UserApprovalFlowType
	// 注入审批条件
	InjectOrm(Orm) error
	// 下一节点
	Yes() string
	// 下一节点
	No() string
	// 审批角色UUID
	RoleUuid() string
	// 上一节点
	Parent() UserApproval
}

type GetUserApproval func(uuid string) (UserApproval, bool)