package response

import (
	"time"
	approvalWorkflowStepsResponse "web-qudo-be/app/module/approval_workflow_steps/response"
	articlesResponse "web-qudo-be/app/module/articles/response"
	usersResponse "web-qudo-be/app/module/users/response"
)

type ArticleApprovalStepLogsResponse struct {
	ID             uint       `json:"id"`
	ApprovalFlowId uint       `json:"approvalFlowId"`
	StepOrder      int        `json:"stepOrder"`
	StepName       string     `json:"stepName"`
	ApprovedById   *uint      `json:"approvedById"`
	Action         string     `json:"action"`
	Message        *string    `json:"message"`
	ProcessedAt    time.Time  `json:"processedAt"`
	UserLevelId    uint       `json:"userLevelId"`
	ClientId       *string    `json:"clientId"`
	CreatedAt      time.Time  `json:"createdAt"`

	// Relations
	ApprovedBy *usersResponse.UsersResponse `json:"approvedBy,omitempty"`
}

type ArticleApprovalStepLogsDetailResponse struct {
	ID                    uint                                                   `json:"id"`
	ArticleApprovalFlowID uint                                                   `json:"articleApprovalFlowId"`
	WorkflowStepID        uint                                                   `json:"workflowStepId"`
	ApproverUserID        *uint                                                  `json:"approverUserId"`
	ApprovalStatusID      uint                                                   `json:"approvalStatusId"`
	ApprovalStatusName    *string                                                `json:"approvalStatusName,omitempty"`
	Comments              *string                                                `json:"comments"`
	ApprovedAt            *time.Time                                             `json:"approvedAt"`
	DueDate               *time.Time                                             `json:"dueDate"`
	IsAutoApproved        bool                                                   `json:"isAutoApproved"`
	CreatedAt             time.Time                                              `json:"createdAt"`
	UpdatedAt             time.Time                                              `json:"updatedAt"`

	// Relations with full details
	WorkflowStep *approvalWorkflowStepsResponse.ApprovalWorkflowStepsResponse `json:"workflowStep,omitempty"`
	ApproverUser *usersResponse.UsersResponse                                  `json:"approverUser,omitempty"`
	Article      *articlesResponse.ArticlesResponse                            `json:"article,omitempty"`
}

type ArticleApprovalStepLogsSummaryResponse struct {
	ID                 uint       `json:"id"`
	WorkflowStepID     uint       `json:"workflowStepId"`
	StepName           string     `json:"stepName"`
	ApproverUserID     *uint      `json:"approverUserId"`
	ApproverUserName   *string    `json:"approverUserName,omitempty"`
	ApprovalStatusID   uint       `json:"approvalStatusId"`
	ApprovalStatusName string     `json:"approvalStatusName"`
	ApprovedAt         *time.Time `json:"approvedAt"`
	DueDate            *time.Time `json:"dueDate"`
	IsAutoApproved     bool       `json:"isAutoApproved"`
}

type ApprovalHistoryResponse struct {
	ArticleID    uint                                      `json:"articleId"`
	ArticleTitle string                                    `json:"articleTitle"`
	WorkflowName string                                    `json:"workflowName"`
	StartedAt    time.Time                                 `json:"startedAt"`
	CompletedAt  *time.Time                                `json:"completedAt"`
	CurrentStep  *string                                   `json:"currentStep"`
	Steps        []ArticleApprovalStepLogsSummaryResponse `json:"steps"`
}

type ApprovalStepStatsResponse struct {
	StepName              string  `json:"stepName"`
	TotalApprovals        int     `json:"totalApprovals"`
	PendingApprovals      int     `json:"pendingApprovals"`
	ApprovedCount         int     `json:"approvedCount"`
	RejectedCount         int     `json:"rejectedCount"`
	AutoApprovedCount     int     `json:"autoApprovedCount"`
	AverageProcessingTime float64 `json:"averageProcessingTime"` // in hours
	OverdueCount          int     `json:"overdueCount"`
}

type UserApprovalStatsResponse struct {
	UserID                uint    `json:"userId"`
	UserName              string  `json:"userName"`
	TotalAssigned         int     `json:"totalAssigned"`
	PendingApprovals      int     `json:"pendingApprovals"`
	CompletedApprovals    int     `json:"completedApprovals"`
	ApprovedCount         int     `json:"approvedCount"`
	RejectedCount         int     `json:"rejectedCount"`
	AverageProcessingTime float64 `json:"averageProcessingTime"` // in hours
	OverdueCount          int     `json:"overdueCount"`
}