package controller

import (
	"narasi-ahli-be/app/module/users/request"
	"narasi-ahli-be/app/module/users/service"
	utilRes "narasi-ahli-be/utils/response"
	"strconv"

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

type userExpertController struct {
	service service.UserExpertService
}

type UserExpertController interface {
	All(c *fiber.Ctx) error
	Show(c *fiber.Ctx) error
}

func NewUserExpertController(
	service service.UserExpertService,
) UserExpertController {
	return &userExpertController{
		service: service,
	}
}

// @Summary      Get list expert users
// @Description  Get users with role expert (user_role_id = 2)
// @Tags         User Expert
// @Param        name query string false "Filter by expert name"
// @Param        type query string false "Filter by expert type"
// @Success      200 {object} response.Response
// @Failure      500 {object} response.InternalServerError
// @Router       /users/experts [get]
func (_i *userExpertController) All(c *fiber.Ctx) error {
	var namePtr *string
	var typePtr *string

	name := c.Query("name")
	if name != "" {
		namePtr = &name
	}

	t := c.Query("type")
	if t != "" {
		typePtr = &t
	}

	req := request.UserExpertQueryRequest{
		Name: namePtr,
		Type: typePtr,
	}

	data, err := _i.service.All(req)
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success: true,
		Data:    data,
	})
}
// Show Expert User
// @Summary      Get expert user detail
// @Description  Get expert user with work, education, and research histories
// @Tags         User Expert
// @Param        id path int true "User ID"
// @Success      200 {object} response.Response
// @Failure      404 {object} response.BadRequestError
// @Failure      500 {object} response.InternalServerError
// @Router       /users/experts/{id} [get]
func (_i *userExpertController) Show(c *fiber.Ctx) error {

	id, err := strconv.ParseUint(c.Params("id"), 10, 64)
	if err != nil {
		return err
	}

	data, err := _i.service.Show(uint(id))
	if err != nil {
		return err
	}

	return utilRes.Resp(c, utilRes.Response{
		Success: true,
		Data:    data,
	})
}

