package request

type CreateApprovalWorkflowStepsRequest struct {
	WorkflowID      uint    `json:"workflowId" validate:"required"`
	StepOrder       int     `json:"stepOrder" validate:"required,min=1"`
	StepName        string  `json:"stepName" validate:"required,min=3,max=100"`
	Description     *string `json:"description" validate:"omitempty,max=500"`
	ApproverRoleID  uint    `json:"approverRoleId" validate:"required"`
	IsOptional      bool    `json:"isOptional"`
	RequiresComment bool    `json:"requiresComment"`
	AutoApprove     bool    `json:"autoApprove"`
	TimeoutHours    *int    `json:"timeoutHours" validate:"omitempty,min=1,max=720"`
}

type UpdateApprovalWorkflowStepsRequest struct {
	StepOrder       *int    `json:"stepOrder" validate:"omitempty,min=1"`
	StepName        *string `json:"stepName" validate:"omitempty,min=3,max=100"`
	Description     *string `json:"description" validate:"omitempty,max=500"`
	ApproverRoleID  *uint   `json:"approverRoleId" validate:"omitempty"`
	IsOptional      *bool   `json:"isOptional"`
	RequiresComment *bool   `json:"requiresComment"`
	AutoApprove     *bool   `json:"autoApprove"`
	TimeoutHours    *int    `json:"timeoutHours" validate:"omitempty,min=1,max=720"`
}

type GetApprovalWorkflowStepsRequest struct {
	WorkflowID  *uint   `json:"workflowId" form:"workflowId"`
	RoleID      *uint   `json:"roleId" form:"roleId"`
	UserLevelID *uint   `json:"userLevelId" form:"userLevelId"`
	StepOrder   *int    `json:"stepOrder" form:"stepOrder"`
	StepName    *string `json:"stepName" form:"stepName"`
	IsOptional  *bool   `json:"isOptional" form:"isOptional"`
	IsActive    *bool   `json:"isActive" form:"isActive"`
	Page        int     `json:"page" form:"page" validate:"min=1"`
	Limit       int     `json:"limit" form:"limit" validate:"min=1,max=100"`
	SortBy      *string `json:"sortBy" form:"sortBy"`
	SortOrder   *string `json:"sortOrder" form:"sortOrder" validate:"omitempty,oneof=asc desc"`
}

type BulkCreateApprovalWorkflowStepsRequest struct {
	WorkflowID uint                                 `json:"workflowId" validate:"required"`
	Steps      []CreateApprovalWorkflowStepsRequest `json:"steps" validate:"required,min=1,max=20,dive"`
}

type ReorderApprovalWorkflowStepsRequest struct {
	StepOrders []struct {
		ID        uint `json:"id" validate:"required"`
		StepOrder int  `json:"stepOrder" validate:"required,min=1"`
	} `json:"stepOrders" validate:"required,min=1,dive"`
}

func (r *ReorderApprovalWorkflowStepsRequest) ToStepOrders() []struct {
	ID        uint
	StepOrder int
} {
	result := make([]struct {
		ID        uint
		StepOrder int
	}, len(r.StepOrders))

	for i, step := range r.StepOrders {
		result[i] = struct {
			ID        uint
			StepOrder int
		}{
			ID:        step.ID,
			StepOrder: step.StepOrder,
		}
	}

	return result
}
