package com.sonic.bear.controller.api;

import com.sonic.bear.domain.input.IdInput;
import com.sonic.bear.domain.output.NicknameOutput;
import com.sonic.bear.lib.input.UserNicknameExistCheckInput;
import com.sonic.bear.lib.input.UserNicknameSyncPoolInput;
import com.sonic.bear.service.UserNicknamePoolService;
import com.sonic.common.rpc.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * API-用户昵称
 * @author coder
 */
@Validated
@RestController
public class UserNicknamePoolApi {

    @Autowired
    private UserNicknamePoolService userNicknamePoolService;

    @ApiOperation(value = "同步昵称数据到数据池", tags = {"API-用户昵称"})
    @PostMapping("/api/user-nickname/sync-pool")
    public Result<Void> syncPool(@RequestBody @Valid UserNicknameSyncPoolInput input) {
        userNicknamePoolService.syncPool(input.getUserId(), input.getUserType(), input.getNickname(), input.getOptType().name());
        return Result.success();
    }

    @ApiOperation(value = "批量查询昵称", tags = {"API-用户昵称"})
    @PostMapping("/api/user-nickname/batch-get")
    public Result<List<NicknameOutput>> batchGetNickname(@RequestBody @Valid IdInput input) {
        return Result.success(userNicknamePoolService.batchGetNickname(input.getUserIdList()));
    }

    @ApiOperation(value = "查询用户昵称是否存在", tags = {"API-用户昵称"})
    @PostMapping("/api/user-nickname/exist-check")
    public Result<Boolean> existCheck(@RequestBody @Valid UserNicknameExistCheckInput input) {
        return Result.success(userNicknamePoolService.existCheck(input.getExUserId(), input.getNickname()));
    }

}
