package com.fs.live.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.SecurityUtils;
import com.fs.company.service.ICompanyRoleService;
import com.fs.live.domain.LiveCommentFeatureConfig;
import com.fs.live.service.ILiveCommentFeatureConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直播评论飘屏/置顶 — 全局规则（库表 config_id=1）
 */
@RestController
@RequestMapping("/live/commentFeature")
public class LiveCommentFeatureConfigController extends BaseController {

    @Autowired
    private ILiveCommentFeatureConfigService liveCommentFeatureConfigService;
    @Autowired
    private ICompanyRoleService companyRoleService;

    @GetMapping("/config")
    public AjaxResult getConfig() {
        return AjaxResult.success(liveCommentFeatureConfigService.getEffectiveConfig());
    }

    /**
     * 可飘屏/可置顶角色多选：下拉选项（去重 role_name）
     */
    @GetMapping("/roles")
    public AjaxResult listDistinctRoleNames() {
        List<String> names = companyRoleService.selectDistinctRoleNames();
        return AjaxResult.success(names);
    }

    @Log(title = "直播评论功能全局配置", businessType = BusinessType.UPDATE)
    @PutMapping("/config")
    public AjaxResult updateConfig(@RequestBody LiveCommentFeatureConfig config) {
        config.setUpdateBy(SecurityUtils.getUsername());
        liveCommentFeatureConfigService.updateConfig(config);
        return AjaxResult.success();
    }
}
