package com.fs.company.controller.qw;

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.framework.service.TokenService;
import com.fs.qw.param.QwGroupChatParam;
import com.fs.qw.service.IQwGroupChatService;
import com.fs.qw.vo.QwGroupChatOptionsVO;
import com.fs.qw.vo.QwGroupChatVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户群详情Controller
 *
 * @author fs
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/qw/groupChat")
public class QwGroupChatController extends BaseController
{
    @Autowired
    private IQwGroupChatService qwGroupChatService;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询客户群详情列表
     */
    @PreAuthorize("@ss.hasPermi('qw:groupChat:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwGroupChatParam qwGroupChat)
    {
        startPage();
        List<QwGroupChatVO> list = qwGroupChatService.selectQwGroupChatList(qwGroupChat);
        return getDataTable(list);
    }


    /**
     * 我的-查询客户群详情列表
     */
    @PreAuthorize("@ss.hasPermi('qw:groupChat:myList')")
    @GetMapping("/myList")
    public TableDataInfo myList(QwGroupChatParam qwGroupChat)
    {
        startPage();
        List<QwGroupChatVO> list = qwGroupChatService.selectQwGroupChatList(qwGroupChat);
        return getDataTable(list);
    }


    /**
     * 获取客户群详情详细信息
     */
//    @PreAuthorize("@ss.hasPermi('qw:groupChat:query')")
    @GetMapping(value = "/{chatId}")
    public AjaxResult getInfo(@PathVariable("chatId") String chatId)
    {
        return AjaxResult.success(qwGroupChatService.selectQwGroupChatByChatId(chatId));
    }

    /**
     *  同步 插入客户群信息
     */
    @GetMapping("/cogradientGroupChat/{corpId}")
    public R cogradientGroupChat(@PathVariable("corpId") String corpId) throws Exception {

//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
//        Long companyId = loginUser.getCompany().getCompanyId();

        return qwGroupChatService.cogradientGroupChat(corpId);
    }

    @GetMapping("/allList/{corpId}")
    public AjaxResult allList(@PathVariable("corpId") String corpId)
    {
//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
//        Long companyId = loginUser.getCompany().getCompanyId();
        List<QwGroupChatOptionsVO> list = qwGroupChatService.selectGroupChatOptionsVOList(corpId);
        return AjaxResult.success(list);
    }
}
