package cn.reghao.tnb.user.app.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.auth.api.iface.AccountQuery;
import cn.reghao.tnb.user.api.dto.UserInfo;
import cn.reghao.tnb.user.app.model.dto.UserProfileUpdate;
import cn.reghao.tnb.user.app.service.UserProfileService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;

/**
 * @author reghao
 * @date 2023-06-22 14:10:07
 */
@Tag(name = "用户资料接口")
@RestController
@RequestMapping("/api/user")
public class UserProfileController {
    @DubboReference(check = false, retries = 0, timeout = 60_000)
    private AccountQuery accountQuery;

    private final UserProfileService userProfileService;

    public UserProfileController(UserProfileService userProfileService) {
        this.userProfileService = userProfileService;
    }

    @Operation(summary = "修改用户资料", description = "N")
    @PostMapping(value = "/profile/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public String updateUserProfile(@RequestBody @Validated UserProfileUpdate userProfileUpdate) {
        userProfileService.updateUserProfile(userProfileUpdate);
        return WebResult.success();
    }

    @Operation(summary = "获取用户资料", description = "N")
    @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserInfo(@RequestParam("userId") String userId) {
        long userId1 = accountQuery.getUserIdLong(userId);
        UserInfo userInfo = userProfileService.getUserInfo(userId1);
        return WebResult.success(userInfo);
    }

    @Operation(summary = "获取推荐用户", description = "N")
    @GetMapping(value = "/discover", produces = MediaType.APPLICATION_JSON_VALUE)
    public String discover() {
        return WebResult.success(Collections.emptyList());
    }
}
