package v1

import (
	dto "quyun/v2/app/http/super/v1/dto"
	"quyun/v2/app/requests"
	"quyun/v2/app/services"

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

// @provider
type users struct{}

// List users
//
// @Router /super/v1/users [get]
// @Summary List users
// @Description List users
// @Tags User
// @Accept json
// @Produce json
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Param username query string false "Username"
// @Success 200 {object} requests.Pager{items=[]dto.UserItem}
// @Bind filter query
func (c *users) List(ctx fiber.Ctx, filter *dto.UserListFilter) (*requests.Pager, error) {
	return services.Super.ListUsers(ctx, filter)
}

// Get user
//
// @Router /super/v1/users/:id<int> [get]
// @Summary Get user
// @Description Get user
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "User ID"
// @Success 200 {object} dto.UserItem
// @Bind id path
func (c *users) Get(ctx fiber.Ctx, id int64) (*dto.UserItem, error) {
	return services.Super.GetUser(ctx, id)
}

// List user tenants
//
// @Router /super/v1/users/:id<int>/tenants [get]
// @Summary List user tenants
// @Description List tenants joined by user
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "User ID"
// @Param page query int false "Page number"
// @Param limit query int false "Page size"
// @Success 200 {object} requests.Pager{items=[]dto.UserTenantItem}
// @Bind id path
// @Bind filter query
func (c *users) ListTenants(ctx fiber.Ctx, id int64, filter *dto.SuperUserTenantListFilter) (*requests.Pager, error) {
	return services.Super.ListUserTenants(ctx, id, filter)
}

// Update user status
//
// @Router /super/v1/users/:id<int>/status [patch]
// @Summary Update user status
// @Description Update user status
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "User ID"
// @Param form body dto.UserStatusUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (c *users) UpdateStatus(ctx fiber.Ctx, id int64, form *dto.UserStatusUpdateForm) error {
	return services.Super.UpdateUserStatus(ctx, id, form)
}

// Update user roles
//
// @Router /super/v1/users/:id<int>/roles [patch]
// @Summary Update user roles
// @Description Update user roles
// @Tags User
// @Accept json
// @Produce json
// @Param id path int64 true "User ID"
// @Param form body dto.UserRolesUpdateForm true "Update form"
// @Success 200 {string} string "Updated"
// @Bind id path
// @Bind form body
func (c *users) UpdateRoles(ctx fiber.Ctx, id int64, form *dto.UserRolesUpdateForm) error {
	return services.Super.UpdateUserRoles(ctx, id, form)
}

// User statistics
//
// @Router /super/v1/users/statistics [get]
// @Summary User statistics
// @Description User statistics
// @Tags User
// @Accept json
// @Produce json
// @Success 200 {array} dto.UserStatistics
func (c *users) Statistics(ctx fiber.Ctx) ([]dto.UserStatistics, error) {
	return services.Super.UserStatistics(ctx)
}

// User statuses
//
// @Router /super/v1/users/statuses [get]
// @Summary User statuses
// @Description User statuses
// @Tags User
// @Accept json
// @Produce json
// @Success 200 {array} requests.KV
func (c *users) Statuses(ctx fiber.Ctx) ([]requests.KV, error) {
	return services.Super.UserStatuses(ctx)
}
