package com.fs.live.controller;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.utils.SecurityUtils;
import com.fs.live.domain.LiveData;
import com.fs.live.param.LiveDataParam;
import com.fs.live.service.ILiveDataService;
import com.fs.live.vo.LiveUserFirstVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/liveData/liveData")
public class LiveDataController extends BaseController {

    @Autowired
    private ILiveDataService liveDataService;

    /**
     * 直播数据页面卡片数据
     */
    @GetMapping("/dashboardData")
    public R dashboardData(@RequestParam Long liveId, HttpServletRequest request) {
        return liveDataService.dashboardData(liveId);
    }

    /**
     * 直播数据页面 分页查询邀请榜单
     */
    @GetMapping("/dashboardInviteList")
    public TableDataInfo inviteList(@RequestParam Long liveId, HttpServletRequest request) {
        startPage();
        List<LiveUserFirstVo> list = liveDataService.inviteList(liveId);
        return getDataTable(list);
    }

    /**
     * 查询新直播数据列表
     */
    @PreAuthorize("@ss.hasPermi('liveData:liveData:list')")
    @PostMapping("/listLiveData")
    public R listLiveData(@RequestBody LiveDataParam param, HttpServletRequest request)
    {
        startPage();
        return liveDataService.listLiveData(param);
    }

    /**
     * 查询直播数据列表
     * */
    @PreAuthorize("@ss.hasPermi('liveData:liveData:query')")
    @GetMapping("/list")
    public List<LiveData> list(LiveData liveData) {
        return liveDataService.selectLiveDataList(liveData);
    }

    /**
     * 查询直播数据详情
     * */
    @PreAuthorize("@ss.hasPermi('liveData:liveData:query')")
    @GetMapping("/get/{liveId}")
    public R getLiveData(@PathVariable Long liveId) {
        return R.ok().put("liveData", liveDataService.selectLiveDataByLiveId(liveId));
    }

    /**
     * 点赞
     * */
    @PreAuthorize("@ss.hasPermi('liveData:liveData:edit')")
    @GetMapping("/like/{liveId}")
    public R like(@PathVariable Long liveId) {
        return R.ok(liveDataService.updateLikeByLiveId(liveId, SecurityUtils.getLoginUser().getUser().getUserId()));
    }

    /**
     * 收藏
     * */
    @PreAuthorize("@ss.hasPermi('liveData:liveData:edit')")
    @GetMapping("/collect/{liveId}")
    public R collect(@PathVariable Long liveId) {
        return R.ok(liveDataService.collect(liveId, SecurityUtils.getLoginUser().getUser().getUserId()));
    }

    /**
     * 关注
     * */
    @PreAuthorize("@ss.hasPermi('liveData:liveData:edit')")
    @GetMapping("/follow/{liveId}")
    public R follow(@PathVariable Long liveId) {
        return R.ok(liveDataService.follow(liveId, SecurityUtils.getLoginUser().getUser().getUserId()));
    }

    /**
     * 获取直播内数据
     * */
    @PreAuthorize("@ss.hasPermi('liveData:liveData:query')")
    @GetMapping("/getLiveViewData")
    public R getLiveViewData(Long liveId) {
        Map<String,Object> liveViewData =liveDataService.getLiveViewData(liveId);
        return R.ok(liveViewData);
    }


}
