package super

import (
	"quyun/v2/app/http/super/dto"
	"quyun/v2/app/requests"
	"quyun/v2/app/services"
	_ "quyun/v2/database/models"
	"quyun/v2/pkg/consts"

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

// @provider
type user struct{}

// list
//
//	@Summary	租户列表
//	@Tags		Super
//	@Accept		json
//	@Produce	json
//	@Param		filter	query		dto.UserPageFilter	true	"Filter"
//	@Success	200		{object}	requests.Pager{items=dto.UserItem}
//
//	@Router		/super/v1/users [get]
//	@Bind		filter query
func (*user) list(ctx fiber.Ctx, filter *dto.UserPageFilter) (*requests.Pager, error) {
	return services.User.Page(ctx, filter)
}

// updateStatus
//
//	@Summary	更新用户状态
//	@Tags		Super
//	@Accept		json
//	@Produce	json
//	@Param		userID	path	int64						true	"UserID"
//	@Param		form	body	dto.UserStatusUpdateForm	true	"Form"
//
//	@Router		/super/v1/users/:userID/status [patch]
//	@Bind		userID path
//	@Bind		form body
func (*user) updateStatus(ctx fiber.Ctx, userID int64, form *dto.UserStatusUpdateForm) error {
	return services.User.UpdateStatus(ctx, userID, form.Status)
}

// statusList
//
//	@Summary	用户状态列表
//	@Tags		Super
//	@Accept		json
//	@Produce	json
//	@Success	200	{array}	requests.KV
//
//	@Router		/super/v1/users/statuses [get]
//	@Bind		userID path
//	@Bind		form body
func (*user) statusList(ctx fiber.Ctx) ([]requests.KV, error) {
	return consts.UserStatusItems(), nil
}

// statistics
//
//	@Summary	用户统计信息
//	@Tags		Super
//	@Accept		json
//	@Produce	json
//	@Success	200	{array}	dto.UserStatistics
//
//	@Router		/super/v1/users/statistics [get]
//	@Bind		userID path
//	@Bind		form body
func (*user) statistics(ctx fiber.Ctx) ([]*dto.UserStatistics, error) {
	return services.User.Statistics(ctx)
}
