package com.fs.live.controller;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
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.LiveCommentPinLog;
import com.fs.live.service.ILiveCommentPinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论置顶：记录、实时监控、后台强制取消
 */
@RestController
@RequestMapping("/live/commentPin")
public class LiveCommentPinAdminController extends BaseController {

    @Autowired
    private ILiveCommentPinService liveCommentPinService;

    /**
     * 全站当前生效置顶（含剩余时间、评论摘要）
     */
    @GetMapping("/monitor/active")
    public AjaxResult monitorActive() {
        return AjaxResult.success(liveCommentPinService.listActiveGlobalMonitor());
    }

    @GetMapping("/log/list")
    public TableDataInfo logList(LiveCommentPinLog query) {
        startPage();
        List<LiveCommentPinLog> list = liveCommentPinService.listPinLogs(query);
        return getDataTable(list);
    }

    /**
     * 某直播间当前置顶列表
     */
    @GetMapping("/active/{liveId}")
    public AjaxResult activeByLive(@PathVariable Long liveId) {
        return AjaxResult.success(liveCommentPinService.listActiveByLiveId(liveId));
    }

    @PostMapping("/active/{activeId}/forceCancel")
    public AjaxResult forceCancel(@PathVariable Long activeId) {
        R r = liveCommentPinService.forceUnpinByActiveId(activeId, SecurityUtils.getUsername());
        if (!Integer.valueOf(200).equals(r.get("code"))) {
            return AjaxResult.error(String.valueOf(r.get("msg")));
        }
        return AjaxResult.success();
    }
}
