package ink.wgink.module.wechat.miniapp.controller.resources;

import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.wechat.miniapp.service.IMiniappUserService;
import ink.wgink.pojo.dtos.miniapp.MiniappUserDTO;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.vos.IdsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: MiniappUserResourceController
 * @Description: 小程序用户接口
 * @Author: wanggeng
 * @Date: 2022/6/22 14:51
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "小程序用户")
@RestController
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/miniapp-user")
public class MiniappUserResourceController {

    @Autowired
    private IMiniappUserService miniappUserService;

    @ApiOperation(value = "通过用户ID删除", notes = "通过用户ID删除接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("delete/user-ids")
    public SuccessResult deleteByUserIds(@RequestBody IdsVO idsVO) {
        if (idsVO.getIds().isEmpty()) {
            throw new ParamsException("id列表不能为空");
        }
        miniappUserService.delete(idsVO.getIds());
        return new SuccessResult();
    }

    @ApiOperation(value = "通过用户ID列表获取列表", notes = "通过ID列表获取列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("list/user-ids")
    public List<MiniappUserDTO> listByUserIds(@RequestBody IdsVO idsVO) {
        if (idsVO.getIds().isEmpty()) {
            throw new ParamsException("id列表不能为空");
        }
        return miniappUserService.listByUserIds(idsVO.getIds());
    }

    @ApiOperation(value = "通过用户编码列表获取列表", notes = "通过用户编码获取列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("list/user-codes")
    public List<MiniappUserDTO> listByUserCodes(@RequestBody IdsVO idsVO) {
        if (idsVO.getIds().isEmpty()) {
            throw new ParamsException("codes列表不能为空");
        }
        return miniappUserService.listByUserCodes(idsVO.getIds());
    }

}
