package controller

import (
	"strconv"
	"web-qudo-be/app/middleware"
	"web-qudo-be/app/module/article_approval_step_logs/request"
	"web-qudo-be/app/module/article_approval_step_logs/service"
	"web-qudo-be/utils/paginator"
	utilRes "web-qudo-be/utils/response"
	utilVal "web-qudo-be/utils/validator"

	"github.com/gofiber/fiber/v2"
	"github.com/rs/zerolog"
)

type articleApprovalStepLogsController struct {
	articleApprovalStepLogsService service.ArticleApprovalStepLogsService
	Log                            zerolog.Logger
}

type ArticleApprovalStepLogsController interface {
	// Basic CRUD
	All(c *fiber.Ctx) error
	Show(c *fiber.Ctx) error
	Save(c *fiber.Ctx) error
	Update(c *fiber.Ctx) error
	Delete(c *fiber.Ctx) error

	// Approval process management
	GetByApprovalFlow(c *fiber.Ctx) error
	GetByWorkflowStep(c *fiber.Ctx) error
	GetByApprover(c *fiber.Ctx) error
	GetPendingApprovals(c *fiber.Ctx) error
	GetOverdueApprovals(c *fiber.Ctx) error

	// Approval actions
	ProcessApproval(c *fiber.Ctx) error
	BulkProcessApproval(c *fiber.Ctx) error
	AutoApprove(c *fiber.Ctx) error

	// History and analytics
	GetApprovalHistory(c *fiber.Ctx) error
	GetApprovalStats(c *fiber.Ctx) error
	GetUserWorkload(c *fiber.Ctx) error
}

func NewArticleApprovalStepLogsController(
	articleApprovalStepLogsService service.ArticleApprovalStepLogsService,
	log zerolog.Logger,
) ArticleApprovalStepLogsController {
	return &articleApprovalStepLogsController{
		articleApprovalStepLogsService: articleApprovalStepLogsService,
		Log:                            log,
	}
}

// All ArticleApprovalStepLogs
// @Summary      Get all ArticleApprovalStepLogs
// @Description  API for getting all ArticleApprovalStepLogs
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        req query request.ArticleApprovalStepLogsQueryRequest false "query parameters"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs [get]
func (_i *articleApprovalStepLogsController) All(c *fiber.Ctx) error {
	paginate, err := paginator.Paginate(c)
	if err != nil {
		return err
	}

	reqContext := request.ArticleApprovalStepLogsQueryRequestContext{
		ApprovalFlowId: c.Query("approvalFlowId"),
		StepId:         c.Query("stepId"),
		ActionById:     c.Query("actionById"),
		ActionType:     c.Query("actionType"),
		StatusId:       c.Query("statusId"),
		ActionDateFrom: c.Query("actionDateFrom"),
		ActionDateTo:   c.Query("actionDateTo"),
		UserLevelId:    c.Query("userLevelId"),
		IsUrgent:       c.Query("isUrgent"),
		Search:         c.Query("search"),
		OrderBy:        c.Query("orderBy"),
		OrderDirection: c.Query("orderDirection"),
	}
	req := reqContext.ToParamRequest()
	req.Pagination = paginate

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	_i.Log.Info().Interface("clientId", clientId).Msg("")

	articleApprovalStepLogsData, paging, err := _i.articleApprovalStepLogsService.GetAll(clientId, *req)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"ArticleApprovalStepLogs list successfully retrieved"},
		Data:     articleApprovalStepLogsData,
		Meta:     paging,
	})
}

// Show ArticleApprovalStepLogs
// @Summary      Get one ArticleApprovalStepLogs
// @Description  API for getting one ArticleApprovalStepLogs
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        id path int true "ArticleApprovalStepLogs ID"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/{id} [get]
func (_i *articleApprovalStepLogsController) Show(c *fiber.Ctx) error {
	id, err := strconv.Atoi(c.Params("id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid ID format")
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.FindOne(clientId, uint(id))
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"ArticleApprovalStepLogs successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}

// Save ArticleApprovalStepLogs
// @Summary      Save ArticleApprovalStepLogs
// @Description  API for saving ArticleApprovalStepLogs
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param 	     payload body request.ArticleApprovalStepLogsCreateRequest true "Required payload"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs [post]
func (_i *articleApprovalStepLogsController) Save(c *fiber.Ctx) error {
	req := new(request.ArticleApprovalStepLogsCreateRequest)
	if err := utilVal.ParseAndValidate(c, req); err != nil {
		return err
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	// Convert request to entity
	entity := req.ToEntity()

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.Create(clientId, entity)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"ArticleApprovalStepLogs successfully created"},
		Data:     articleApprovalStepLogsData,
	})
}

// Update ArticleApprovalStepLogs
// @Summary      Update ArticleApprovalStepLogs
// @Description  API for updating ArticleApprovalStepLogs
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        id path int true "ArticleApprovalStepLogs ID"
// @Param 	     payload body request.ArticleApprovalStepLogsUpdateRequest true "Required payload"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/{id} [put]
func (_i *articleApprovalStepLogsController) Update(c *fiber.Ctx) error {
	id, err := strconv.Atoi(c.Params("id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid ID format")
	}

	req := new(request.ArticleApprovalStepLogsUpdateRequest)
	if err := utilVal.ParseAndValidate(c, req); err != nil {
		return err
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	// Convert request to entity
	entity := req.ToEntity()

	err = _i.articleApprovalStepLogsService.Update(clientId, uint(id), entity)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"ArticleApprovalStepLogs successfully updated"},
	})
}

// Delete ArticleApprovalStepLogs
// @Summary      Delete ArticleApprovalStepLogs
// @Description  API for deleting ArticleApprovalStepLogs
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        id path int true "ArticleApprovalStepLogs ID"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/{id} [delete]
func (_i *articleApprovalStepLogsController) Delete(c *fiber.Ctx) error {
	id, err := strconv.Atoi(c.Params("id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid ID format")
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	err = _i.articleApprovalStepLogsService.Delete(clientId, uint(id))
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"ArticleApprovalStepLogs successfully deleted"},
	})
}

// GetByApprovalFlow ArticleApprovalStepLogs
// @Summary      Get ArticleApprovalStepLogs by Approval Flow ID
// @Description  API for getting ArticleApprovalStepLogs by Approval Flow ID
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        flow_id path int true "Approval Flow ID"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/flow/{flow_id} [get]
func (_i *articleApprovalStepLogsController) GetByApprovalFlow(c *fiber.Ctx) error {
	flowId, err := strconv.Atoi(c.Params("flow_id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid flow ID format")
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.GetByApprovalFlowID(clientId, uint(flowId))
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"ArticleApprovalStepLogs by approval flow successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}

// GetByWorkflowStep ArticleApprovalStepLogs
// @Summary      Get ArticleApprovalStepLogs by Workflow Step ID
// @Description  API for getting ArticleApprovalStepLogs by Workflow Step ID
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        step_id path int true "Workflow Step ID"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/step/{step_id} [get]
func (_i *articleApprovalStepLogsController) GetByWorkflowStep(c *fiber.Ctx) error {
	stepId, err := strconv.Atoi(c.Params("step_id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid step ID format")
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.GetByWorkflowStepID(clientId, uint(stepId))
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"ArticleApprovalStepLogs by workflow step successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}

// GetByApprover ArticleApprovalStepLogs
// @Summary      Get ArticleApprovalStepLogs by Approver User ID
// @Description  API for getting ArticleApprovalStepLogs by Approver User ID
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        user_id path int true "Approver User ID"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/approver/{user_id} [get]
func (_i *articleApprovalStepLogsController) GetByApprover(c *fiber.Ctx) error {
	userId, err := strconv.Atoi(c.Params("user_id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid user ID format")
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.GetByApproverUserID(clientId, uint(userId))
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"ArticleApprovalStepLogs by approver successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}

// GetPendingApprovals ArticleApprovalStepLogs
// @Summary      Get Pending Approvals
// @Description  API for getting pending approvals
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        user_id query int false "Filter by user ID"
// @Param        role_id query int false "Filter by role ID"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/pending [get]
func (_i *articleApprovalStepLogsController) GetPendingApprovals(c *fiber.Ctx) error {
	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	var userID *uint
	var roleID *uint

	if userIDStr := c.Query("user_id"); userIDStr != "" {
		if id, err := strconv.Atoi(userIDStr); err == nil {
			userIDVal := uint(id)
			userID = &userIDVal
		}
	}

	if roleIDStr := c.Query("role_id"); roleIDStr != "" {
		if id, err := strconv.Atoi(roleIDStr); err == nil {
			roleIDVal := uint(id)
			roleID = &roleIDVal
		}
	}

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.GetPendingApprovals(clientId, userID, roleID)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"Pending approvals successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}

// GetOverdueApprovals ArticleApprovalStepLogs
// @Summary      Get Overdue Approvals
// @Description  API for getting overdue approvals
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        user_id query int false "Filter by user ID"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/overdue [get]
func (_i *articleApprovalStepLogsController) GetOverdueApprovals(c *fiber.Ctx) error {
	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	var userID *uint
	if userIDStr := c.Query("user_id"); userIDStr != "" {
		if id, err := strconv.Atoi(userIDStr); err == nil {
			userIDVal := uint(id)
			userID = &userIDVal
		}
	}

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.GetOverdueApprovals(clientId, userID)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"Overdue approvals successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}

// ProcessApproval ArticleApprovalStepLogs
// @Summary      Process Approval
// @Description  API for processing approval step
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        id path int true "Step Log ID"
// @Param 	     payload body request.ProcessApprovalRequest true "Required payload"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/{id}/process [post]
func (_i *articleApprovalStepLogsController) ProcessApproval(c *fiber.Ctx) error {
	id, err := strconv.Atoi(c.Params("id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid ID format")
	}

	req := new(request.ProcessApprovalRequest)
	if err := utilVal.ParseAndValidate(c, req); err != nil {
		return err
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	err = _i.articleApprovalStepLogsService.ProcessApproval(clientId, uint(id), req.UserID, req.StatusID, req.Comments)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"Approval processed successfully"},
	})
}

// BulkProcessApproval ArticleApprovalStepLogs
// @Summary      Bulk Process Approvals
// @Description  API for bulk processing approval steps
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param 	     payload body request.BulkProcessApprovalRequest true "Required payload"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/bulk-process [post]
func (_i *articleApprovalStepLogsController) BulkProcessApproval(c *fiber.Ctx) error {
	req := new(request.BulkProcessApprovalRequest)
	if err := utilVal.ParseAndValidate(c, req); err != nil {
		return err
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	err := _i.articleApprovalStepLogsService.BulkProcessApproval(clientId, req.LogIDs, req.UserID, req.StatusID, req.Comments)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"Approvals processed successfully"},
	})
}

// AutoApprove ArticleApprovalStepLogs
// @Summary      Auto Approve Step
// @Description  API for automatically approving a step
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        id path int true "Step Log ID"
// @Param        reason query string true "Auto approval reason"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/{id}/auto-approve [post]
func (_i *articleApprovalStepLogsController) AutoApprove(c *fiber.Ctx) error {
	id, err := strconv.Atoi(c.Params("id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid ID format")
	}

	reason := c.Query("reason")
	if reason == "" {
		return utilRes.ErrorBadRequest(c, "Reason is required")
	}

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	err = _i.articleApprovalStepLogsService.AutoApprove(clientId, uint(id), reason)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"Step auto approved successfully"},
	})
}

// GetApprovalHistory ArticleApprovalStepLogs
// @Summary      Get Approval History
// @Description  API for getting approval history
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        article_id query int false "Filter by article ID"
// @Param        user_id query int false "Filter by user ID"
// @Param        from_date query string false "Filter from date (YYYY-MM-DD)"
// @Param        to_date query string false "Filter to date (YYYY-MM-DD)"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/history [get]
func (_i *articleApprovalStepLogsController) GetApprovalHistory(c *fiber.Ctx) error {
	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	var articleID *uint
	var userID *uint
	filters := make(map[string]interface{})

	if articleIDStr := c.Query("article_id"); articleIDStr != "" {
		if id, err := strconv.Atoi(articleIDStr); err == nil {
			articleIDVal := uint(id)
			articleID = &articleIDVal
		}
	}

	if userIDStr := c.Query("user_id"); userIDStr != "" {
		if id, err := strconv.Atoi(userIDStr); err == nil {
			userIDVal := uint(id)
			userID = &userIDVal
		}
	}

	if fromDate := c.Query("from_date"); fromDate != "" {
		filters["from_date"] = fromDate
	}

	if toDate := c.Query("to_date"); toDate != "" {
		filters["to_date"] = toDate
	}

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.GetApprovalHistory(clientId, articleID, userID, filters)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"Approval history successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}

// GetApprovalStats ArticleApprovalStepLogs
// @Summary      Get Approval Statistics
// @Description  API for getting approval statistics
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        from_date query string false "Filter from date (YYYY-MM-DD)"
// @Param        to_date query string false "Filter to date (YYYY-MM-DD)"
// @Param        workflow_id query int false "Filter by workflow ID"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/stats [get]
func (_i *articleApprovalStepLogsController) GetApprovalStats(c *fiber.Ctx) error {
	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	filters := make(map[string]interface{})

	if fromDate := c.Query("from_date"); fromDate != "" {
		filters["from_date"] = fromDate
	}

	if toDate := c.Query("to_date"); toDate != "" {
		filters["to_date"] = toDate
	}

	if workflowID := c.Query("workflow_id"); workflowID != "" {
		if id, err := strconv.Atoi(workflowID); err == nil {
			filters["workflow_id"] = id
		}
	}

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.GetApprovalStats(clientId, filters)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"Approval statistics successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}

// GetUserWorkload ArticleApprovalStepLogs
// @Summary      Get User Workload
// @Description  API for getting user workload statistics
// @Tags         ArticleApprovalStepLogs
// @Security     Bearer
// @Param        X-Client-Key header string true "Insert the X-Client-Key"
// @Param        user_id path int true "User ID"
// @Param        include_stats query bool false "Include detailed statistics"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.BadRequestError
// @Failure      401  {object}  response.UnauthorizedError
// @Failure      500  {object}  response.InternalServerError
// @Router       /article-approval-step-logs/user/{user_id}/workload [get]
func (_i *articleApprovalStepLogsController) GetUserWorkload(c *fiber.Ctx) error {
	userId, err := strconv.Atoi(c.Params("user_id"))
	if err != nil {
		return utilRes.ErrorBadRequest(c, "Invalid user ID format")
	}

	includeStats := c.Query("include_stats") == "true"

	// Get ClientId from context
	clientId := middleware.GetClientID(c)

	articleApprovalStepLogsData, err := _i.articleApprovalStepLogsService.GetUserWorkload(clientId, uint(userId), includeStats)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success:  true,
		Messages: utilRes.Messages{"User workload successfully retrieved"},
		Data:     articleApprovalStepLogsData,
	})
}
