package cn.reghao.tnb.user.app.controller;

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.user.api.dto.UserInfo;
import cn.reghao.tnb.user.api.dto.VipPlanInfo;
import cn.reghao.tnb.user.api.dto.WalletChargeDto;
import cn.reghao.tnb.user.app.service.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2025-09-26 20:04:21
 */
@Tag(name = "user 管理接口")
@RestController
@RequestMapping("/api/admin/user")
public class AdminUserController {
    private final AdminUserService adminUserService;
    
    public AdminUserController(AdminUserService adminUserService) {
        this.adminUserService = adminUserService;
    }

    @Operation(summary = "用户帐号列表页面", description = "N")
    @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    public String indexPage(@RequestParam(value = "nextId", required = false) Integer nextId) {
        PageList<UserInfo> pageList = adminUserService.getUserList(1);
        return WebResult.success(pageList);
    }

    @Operation(summary = "充值请求列表页面", description = "N")
    @GetMapping(value = "/charge", produces = MediaType.APPLICATION_JSON_VALUE)
    public String chargeReq(@RequestParam("pn") int pageNumber) {
        List<WalletChargeDto> list = adminUserService.getChargeReqs();
        return WebResult.success(list);
    }

    @Operation(summary = "同意用户充值", description = "N")
    @PostMapping(value = "/charge/approve/{chargeId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String approveCharge(@PathVariable("chargeId") Long chargeId) {
        adminUserService.approve(chargeId);
        return WebResult.success();
    }

    @Operation(summary = "同意所有用户充值", description = "N")
    @PostMapping(value = "/charge/approve_all", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String approveAllCharge() {
        adminUserService.approveAll();
        return WebResult.success();
    }

    @Operation(summary = "拒绝用户充值", description = "N")
    @PostMapping(value = "/charge/decline/{chargeId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String declineCharge(@PathVariable("chargeId") Long chargeId) {
        adminUserService.decline(chargeId);
        return WebResult.success();
    }

    @Operation(summary = "会员计划列表页面", description = "N")
    @GetMapping(value = "/vip_plan", produces = MediaType.APPLICATION_JSON_VALUE)
    public String vipPage() {
        List<VipPlanInfo> list = adminUserService.getVipPlans();
        return WebResult.success(list);
    }

    @Operation(summary = "获取当前在线用户", description = "N")
    @GetMapping("/online_users")
    public String getOnlineUsers() {
        return WebResult.success();
    }
}
