package cn.reghao.tnb.content.app.vod.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.auth.api.iface.AccountQuery;
import cn.reghao.tnb.content.app.vod.model.vo.UserContentData;
import cn.reghao.tnb.content.app.vod.service.AdminVodService;
import cn.reghao.tnb.content.app.vod.service.ContentService;
import cn.reghao.tnb.content.app.vod.service.LogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2023-08-20 00:51:11
 */
@Slf4j
@Tag(name = "内容接口")
@RestController
@RequestMapping("/api/content")
public class ContentController {
    @DubboReference(check = false, retries = 0, timeout = 60_000)
    private AccountQuery accountQuery;

    private final AdminVodService adminVodService;
    private final ContentService contentService;

    public ContentController(AdminVodService adminVodService, ContentService contentService) {
        this.adminVodService = adminVodService;
        this.contentService = contentService;
    }

    @Operation(summary = "获取站点公告", description = "N")
    @GetMapping("/site/notice")
    public String getSiteNotice() {
        String notice = adminVodService.getSiteNotice();
        return WebResult.success(notice);
    }

    @Operation(summary = "获取用户内容数据", description = "N")
    @GetMapping(value = "/userdata", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserContentData(@RequestParam("userId") String userId) {
        long userId1 = accountQuery.getUserIdLong(userId);
        UserContentData userContentData = contentService.getUserContentData(userId1);
        return WebResult.success(userContentData);
    }

    @Autowired
    LogService logService;
    @GetMapping("/log")
    public String getLogConfig() {
        return WebResult.success(logService.getLogProperties());
    }
}
