package com.auth.service.base.controller;

import com.auth.common.model.common.result.PageResult;
import com.auth.common.model.common.result.Result;
import com.auth.common.model.common.result.ResultCodeEnum;
import com.auth.model.base.dto.UserDto;
import com.auth.model.base.vo.UserVo;
import com.auth.dao.base.entity.UserEntity;
import com.auth.service.base.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户信息 前端控制器
 * </p>
 *
 * @author AuthoritySystem
 * @since 2025-07-17 23:06:38
 */
@Tag(name = "用户信息", description = "用户信息相关接口")
@RestController
@RequestMapping("/api/v1/base/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @Operation(summary = "分页查询用户信息", description = "分页查询用户信息")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<UserVo>> getUserPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            UserDto dto) {
        Page<UserEntity> pageParams = new Page<>(page, limit);
        PageResult<UserVo> pageResult = userService.getUserPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "根据id查询用户信息详情", description = "根据id查询用户信息详情")
    @GetMapping("{id}")
    public Result<UserVo> getUserById(@PathVariable("id") Long id) {
        UserVo userVo = userService.getUserById(id);

        return Result.success(userVo);
    }

    @Operation(summary = "添加用户信息", description = "添加用户信息")
    @PostMapping()
    public Result<String> addUser(@Valid @RequestBody UserDto dto) {
        userService.addUser(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新用户信息", description = "更新用户信息")
    @PutMapping()
    public Result<String> updateUser(@Valid @RequestBody UserDto dto) {
        userService.updateUser(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除用户信息", description = "删除用户信息")
    @DeleteMapping()
    public Result<String> deleteUser(@RequestBody List<Long> ids) {
        userService.deleteUser(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}