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

import cn.reghao.jutil.web.WebResult;
import cn.reghao.tnb.account.api.dto.CrawledUser;
import cn.reghao.tnb.user.app.service.CrawledUserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2024-09-27 15:15:50
 */
@Tag(name = "爬取的用户资料接口")
@RestController
@RequestMapping("/api/user")
public class CrawledUserController {
    private final CrawledUserService crawledUserService;

    public CrawledUserController(CrawledUserService crawledUserService) {
        this.crawledUserService = crawledUserService;
    }

    @Operation(summary = "创建 bilibili 用户帐号", description = "N")
    @PostMapping("/create/bili")
    public String updateUserProfile(@RequestBody @Validated CrawledUser crawledUser) {
        Long userId = crawledUserService.createAccount(crawledUser);
        return WebResult.success(userId);
    }

    @Operation(summary = "查找 bilibili 用户", description = "N")
    @GetMapping(value = "/search", produces = MediaType.APPLICATION_JSON_VALUE)
    public String searchUser(@RequestParam("username") String username) {
        Long userId = crawledUserService.getUserId(username);
        return WebResult.success(userId);
    }
}
