package com.mmc.iuav.user.controller;

import com.mmc.iuav.group.Page;
import com.mmc.iuav.group.Update;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.dto.UserAccountSimpleDTO;
import com.mmc.iuav.user.model.qo.UserAccountQO;
import com.mmc.iuav.user.model.vo.UserAccountVO;
import com.mmc.iuav.user.service.UserAccountService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author: zj
 * @Date: 2023/5/15 15:32
 */
@Api(tags = "账号相关接口")
@RequestMapping("/user-account/")
@RestController
public class UserAccountController extends BaseController{

    @Autowired
    private UserAccountService userAccountService;

    @ApiOperation(value = "客户列表")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = UserAccountVO.class) })
    @PostMapping("listAppUser")
    public ResultBody<UserAccountVO> listAppUser(@Validated(value = {Page.class})@RequestBody UserAccountQO userAccountQO){
        return userAccountService.listAppUser(userAccountQO);
    }

    @ApiOperation(value = "获取用户信息")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = UserAccountVO.class) })
    @GetMapping("info")
    public ResultBody info(HttpServletRequest request) {
        return ResultBody.success(userAccountService.getUserAccountById(this.getUserLoginInfoFromRedis(request).getUserAccountId()));
    }

    @ApiOperation(value = "修改用户信息")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = ResultBody.class) })
    @PostMapping("update")
    public ResultBody update(@Validated(value = {Update.class})@RequestBody UserAccountVO userAccountVO){
        return userAccountService.update(userAccountVO);
    }

    @ApiOperation(value = "获取用户基本信息", hidden = true)
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = UserAccountSimpleDTO.class) })
    @GetMapping("feignGetUserSimpleInfo")
    public UserAccountSimpleDTO feignGetUserSimpleInfo(@RequestParam Integer userAccountId){
        return userAccountService.getUserSimpleInfo(userAccountId);
    }

    @ApiOperation(value = "根据用户地区查询后台用户id", hidden = true)
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = UserAccountSimpleDTO.class) })
    @GetMapping("feignListUserAccountIds")
    public List<Integer>feignListUserAccountIds(@RequestParam Integer provinceCode, @RequestParam(required = false) Integer cityCode, @RequestParam(required = false) Integer districtCode){
        return userAccountService.feignListUserAccountIds(provinceCode, cityCode, districtCode);
    }

    @ApiOperation(value = "授权手机号")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = Integer.class) })
    @GetMapping("getUserPhoneNumber")
    public ResultBody getUserPhoneNumber(HttpServletRequest request,
            @ApiParam(value = "授权手机号code", required = true) @RequestParam String code) {
        return userAccountService.getUserPhoneNumber(this.getUserLoginInfoFromRedis(request).getUserAccountId(), code);
    }

    @ApiOperation(value = "根据用户id查询用户信息", hidden = true)
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = UserAccountSimpleDTO.class) })
    @PostMapping("feignListUserAccountByIds")
    public List<UserAccountSimpleDTO> feignListUserAccountByIds(@RequestBody List<Integer> ids){
        return userAccountService.feignListUserAccountByIds(ids);
    }

    @ApiOperation(value = "根据用户ids上级推荐人信息", hidden = true)
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = UserAccountSimpleDTO.class) })
    @PostMapping("feignListRcdUserInfo")
    public List<UserAccountSimpleDTO> feignListRcdUserInfo(@RequestBody List<Integer> userIds){
        return userAccountService.feignListRcdUserInfo(userIds);
    }

    @ApiOperation(value = "查询上级推荐人id", hidden = true)
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = Integer.class) })
    @GetMapping("feignGetSuperiorRef")
    public Integer feignGetSuperiorRef(@RequestParam Integer userAccountId){
        return userAccountService.feignGetSuperiorRef(userAccountId);
    }

    @ApiOperation(value = "查询上级推荐人信息", hidden = true)
    @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = UserAccountSimpleDTO.class) })
    @GetMapping("feignGetUserRcdInfo")
    public UserAccountSimpleDTO feignGetUserRcdInfo(@RequestParam Integer userAccountId){
        return userAccountService.feignGetUserRcdInfo(userAccountId);
    }

}
