package response

import (
	"time"
	articlesResponse "web-qudo-be/app/module/articles/response"
	approvalWorkflowsResponse "web-qudo-be/app/module/approval_workflows/response"
	articleApprovalStepLogsResponse "web-qudo-be/app/module/article_approval_step_logs/response"
)

type ArticleApprovalFlowsResponse struct {
	ID                  uint       `json:"id"`
	ArticleID           uint       `json:"articleId"`
	WorkflowID          uint       `json:"workflowId"`
	CurrentStep         int        `json:"currentStep"`
	Status              string     `json:"status"`
	SubmittedBy         uint       `json:"submittedBy"`
	SubmittedAt         time.Time  `json:"submittedAt"`
	CompletedAt         *time.Time `json:"completedAt"`
	RejectedAt          *time.Time `json:"rejectedAt"`
	RejectionReason     *string    `json:"rejectionReason"`
	RevisionRequestedAt *time.Time `json:"revisionRequestedAt"`
	RevisionReason      *string    `json:"revisionReason"`
	ResubmittedAt       *time.Time `json:"resubmittedAt"`
	CreatedAt           time.Time  `json:"createdAt"`
	UpdatedAt           time.Time  `json:"updatedAt"`

	// Relations
	Article  *articlesResponse.ArticlesResponse                                     `json:"article,omitempty"`
	Workflow *approvalWorkflowsResponse.ApprovalWorkflowsResponse                  `json:"workflow,omitempty"`
	StepLogs []*articleApprovalStepLogsResponse.ArticleApprovalStepLogsResponse    `json:"stepLogs,omitempty"`
}

type ArticleApprovalFlowsDetailResponse struct {
	ID                  uint       `json:"id"`
	ArticleID           uint       `json:"articleId"`
	WorkflowID          uint       `json:"workflowId"`
	CurrentStep         int        `json:"currentStep"`
	Status              string     `json:"status"`
	SubmittedBy         uint       `json:"submittedBy"`
	SubmittedByName     string     `json:"submittedByName"`
	SubmittedAt         time.Time  `json:"submittedAt"`
	CompletedAt         *time.Time `json:"completedAt"`
	RejectedAt          *time.Time `json:"rejectedAt"`
	RejectionReason     *string    `json:"rejectionReason"`
	RevisionRequestedAt *time.Time `json:"revisionRequestedAt"`
	RevisionReason      *string    `json:"revisionReason"`
	ResubmittedAt       *time.Time `json:"resubmittedAt"`
	CreatedAt           time.Time  `json:"createdAt"`
	UpdatedAt           time.Time  `json:"updatedAt"`

	// Relations with full details
	Article  *articlesResponse.ArticlesResponse                                     `json:"article"`
	Workflow *approvalWorkflowsResponse.ApprovalWorkflowsWithStepsResponse        `json:"workflow"`
	StepLogs []*articleApprovalStepLogsResponse.ArticleApprovalStepLogsResponse    `json:"stepLogs"`
}

type ArticleApprovalFlowsSummaryResponse struct {
	ID              uint      `json:"id"`
	ArticleID       uint      `json:"articleId"`
	ArticleTitle    string    `json:"articleTitle"`
	WorkflowName    string    `json:"workflowName"`
	CurrentStep     int       `json:"currentStep"`
	TotalSteps      int       `json:"totalSteps"`
	Status          string    `json:"status"`
	SubmittedBy     uint      `json:"submittedBy"`
	SubmittedByName string    `json:"submittedByName"`
	SubmittedAt     time.Time `json:"submittedAt"`
	DaysInApproval  int       `json:"daysInApproval"`
}

type ApprovalQueueResponse struct {
	ID                uint      `json:"id"`
	ArticleID         uint      `json:"articleId"`
	ArticleTitle      string    `json:"articleTitle"`
	ArticleAuthor     string    `json:"articleAuthor"`
	WorkflowName      string    `json:"workflowName"`
	CurrentStepName   string    `json:"currentStepName"`
	SubmittedAt       time.Time `json:"submittedAt"`
	DaysWaiting       int       `json:"daysWaiting"`
	Priority          string    `json:"priority"`
	RequiresComment   bool      `json:"requiresComment"`
}

type ApprovalDashboardStatsResponse struct {
	PendingApprovals    int `json:"pendingApprovals"`
	MyPendingApprovals  int `json:"myPendingApprovals"`
	ApprovedToday       int `json:"approvedToday"`
	RejectedToday       int `json:"rejectedToday"`
	RevisionRequested   int `json:"revisionRequested"`
	OverdueApprovals    int `json:"overdueApprovals"`
	AverageApprovalTime int `json:"averageApprovalTime"` // in hours
}

type ApprovalWorkloadStatsResponse struct {
	ApproverID          uint   `json:"approverId"`
	ApproverName        string `json:"approverName"`
	PendingCount        int    `json:"pendingCount"`
	ApprovedThisWeek    int    `json:"approvedThisWeek"`
	RejectedThisWeek    int    `json:"rejectedThisWeek"`
	AverageResponseTime int    `json:"averageResponseTime"` // in hours
}

type ApprovalAnalyticsResponse struct {
	Period              string  `json:"period"`
	TotalSubmissions    int     `json:"totalSubmissions"`
	TotalApproved       int     `json:"totalApproved"`
	TotalRejected       int     `json:"totalRejected"`
	TotalRevisions      int     `json:"totalRevisions"`
	ApprovalRate        float64 `json:"approvalRate"`
	AverageApprovalTime float64 `json:"averageApprovalTime"` // in hours
}