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

import cn.reghao.jutil.jdk.serializer.JsonConverter;
import cn.reghao.tnb.content.api.dto.VideoRegion;
import cn.reghao.tnb.content.app.mobile.service.AndroidService;
import cn.reghao.tnb.content.app.mobile.model.VideoBeanResult;
import cn.reghao.tnb.content.app.mobile.model.VideoDetailsResult;
import cn.reghao.tnb.content.app.mobile.model.VideoRegionResult;
import cn.reghao.tnb.content.app.mobile.model.play.HDVideoInfo;
import cn.reghao.tnb.content.app.mobile.model.search.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author reghao
 * @date 2023-09-02 01:03:06
 */
@Tag(name = "移动端内容接口")
@RestController
@RequestMapping("/api/content/m")
public class AndroidController {
    private final AndroidService androidService;

    public AndroidController(AndroidService androidService) {
        this.androidService = androidService;
    }

    @GetMapping(value = "/hotword", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserContentData10() {
        HotSearchTag hotSearchTag = androidService.getSearchTag();
        return JsonConverter.objectToJson(hotSearchTag);
    }

    @GetMapping(value = "/search", produces = MediaType.APPLICATION_JSON_VALUE)
    public String search(@RequestParam("keyword") String keyword, @RequestParam("pn") int pn, @RequestParam("ps") int ps) {
        List<NavBean> navBeans = androidService.searchAll(keyword);
        SearchArchiveResult searchArchiveResult = new SearchArchiveResult();
        searchArchiveResult.setNavBeans(navBeans);
        return JsonConverter.objectToJson(searchArchiveResult);
    }

    @GetMapping(value = "/search/user", produces = MediaType.APPLICATION_JSON_VALUE)
    public String searchUser(@RequestParam("keyword") String keyword, @RequestParam("pn") int pn, @RequestParam("ps") int ps) {
        SearchUpperInfo searchArchiveInfo = androidService.searchUser(keyword);
        return JsonConverter.objectToJson(searchArchiveInfo);
    }

    @GetMapping(value = "/search/video", produces = MediaType.APPLICATION_JSON_VALUE)
    public String searchVideo(@RequestParam("keyword") String keyword, @RequestParam("pn") int pn, @RequestParam("ps") int ps) {
        SearchVideoResult searchVideoResult = androidService.searchVideo(keyword);
        return JsonConverter.objectToJson(searchVideoResult);
    }

    @GetMapping(value = "/category", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getCategory() {
        List<VideoRegion> list = androidService.getCategories();
        VideoRegionResult videoRegionResult = new VideoRegionResult(list);
        return JsonConverter.objectToJson(videoRegionResult);
    }

    @GetMapping(value = "/category/video", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getCategoryVideo() {
        VideoBeanResult videoBeanResult = androidService.getCategoryVideo();
        return JsonConverter.objectToJson(videoBeanResult);
    }

    @Operation(summary = "用户内容数据")
    @GetMapping(value = "/recommend", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserContentData(@RequestParam("platform") String platform,
                                     @RequestParam("device") String device,
                                     @RequestParam("build") String build) {

        VideoBeanResult videoBeanResult = androidService.getRecommend();
        return JsonConverter.objectToJson(videoBeanResult);
    }

    @GetMapping(value = "/video/{videoId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserContentData1(@PathVariable("videoId") String videoId) {
        VideoDetailsResult videoDetailsResult = androidService.getVideoDetailsResult(videoId);
        return JsonConverter.objectToJson(videoDetailsResult);
    }

    @GetMapping(value = "/video/url/{videoId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserContentData2(@PathVariable("videoId") String videoId) {
        HDVideoInfo videoInfo = androidService.getVideoUrl(videoId);
        return JsonConverter.objectToJson(videoInfo);
    }

    @GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserInfo(@RequestParam("userId") Long userId) {
        return JsonConverter.objectToJson(new Object());
    }
}
