package cn.reghao.tnb.admin.controller;

import cn.reghao.tnb.admin.db.mapper.TnbUserMapper;
import cn.reghao.tnb.admin.model.po.TnbUser;
import cn.reghao.tnb.admin.service.AdminService;
import cn.reghao.tnb.common.web.WebResult;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author reghao
 * @date 2026-01-21 14:02:38
 */
@RestController
@RequestMapping("/api/admin1")
public class AdminController {
    private final AdminService adminService;
    private TnbUserMapper tnbUserMapper;

    public AdminController(AdminService adminService, TnbUserMapper tnbUserMapper) {
        this.adminService = adminService;
        this.tnbUserMapper = tnbUserMapper;
    }

    @Operation(summary = "", description = "N")
    @GetMapping(value = "/stat", produces = MediaType.APPLICATION_JSON_VALUE)
    public String stat() {
        adminService.stat();
        List<TnbUser> list = tnbUserMapper.findAll();
        return WebResult.success(list);
    }

    @Operation(summary = "", description = "N")
    @GetMapping(value = "/stat1", produces = MediaType.APPLICATION_JSON_VALUE)
    public String stat1() {
        tnbUserMapper.updateUsername(1, "gggg");
        return WebResult.success("update");
    }

    @Operation(summary = "", description = "N")
    @GetMapping(value = "/stat2", produces = MediaType.APPLICATION_JSON_VALUE)
    public String stat2() {
        tnbUserMapper.deleteById(1);
        return WebResult.success("delete");
    }

    @Operation(summary = "", description = "N")
    @GetMapping(value = "/stat3", produces = MediaType.APPLICATION_JSON_VALUE)
    public String stat3() {
        TnbUser tnbUser = new TnbUser();
        tnbUser.setUsername("reghao");
        tnbUserMapper.save(tnbUser);
        return WebResult.success("add");
    }
}
