package com.sonic.bear.controller.api;

import com.sonic.bear.lib.input.UserIdInput;
import com.sonic.bear.lib.input.UserIdListInput;
import com.sonic.bear.lib.output.BaseUserInfoOutput;
import com.sonic.bear.lib.output.UserInfoListOutput;
import com.sonic.bear.service.UserSearchService;
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 UserSearchApi {

    @Autowired
    private UserSearchService userSearchService;

    @ApiOperation(value = "批量获取用户基础信息", tags = {"API-用户查询"})
    @PostMapping("/api/user/batch-get-info")
    public Result<List<UserInfoListOutput>> batchGetUserInfo(@RequestBody @Valid UserIdListInput input) {
        return Result.success(userSearchService.batchGetUserInfo(input.getUserIdList()));
    }

    @ApiOperation(value = "获取用户自己的基础信息", tags = {"API-用户查询"})
    @PostMapping("/api/user/base-user-info")
    public Result<BaseUserInfoOutput> baseUserInfo(@RequestBody @Valid UserIdInput input) {
        return Result.success(userSearchService.baseUserInfo(input.getUserId()));
    }


}
