package com.ruoyi.web.modules.diagnosis.controller;

import java.util.List;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.modules.diagnosis.domain.BizConsultMessage;
import com.ruoyi.web.modules.diagnosis.domain.BizConsultSession;
import com.ruoyi.web.modules.diagnosis.domain.VetConsultSendBody;
import com.ruoyi.web.modules.diagnosis.service.IBizVetOnlineConsultService;

/**
 * 在线接诊（兽医）
 */
@RestController
@RequestMapping("/diseaseTreatment/onlineConsult/vet")
public class BizVetOnlineConsultController extends BaseController
{
    @Autowired
    private IBizVetOnlineConsultService bizVetOnlineConsultService;

    @PreAuthorize("@ss.hasPermi('diseaseTreatment:vetOnlineConsult:list')")
    @GetMapping("/session/list")
    public TableDataInfo list(BizConsultSession query,
            @RequestParam(value = "searchMode", required = false) Boolean searchMode)
    {
        if (query == null)
        {
            query = new BizConsultSession();
        }
        query.setSearchMode(searchMode);
        startPage();
        List<BizConsultSession> list = bizVetOnlineConsultService.selectVetSessionList(query,
                SecurityUtils.getUserId());
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('diseaseTreatment:vetOnlineConsult:query')")
    @GetMapping("/session/{sessionId}/messages")
    public AjaxResult messages(@PathVariable("sessionId") Long sessionId,
            @RequestParam(value = "beforeId", required = false) Long beforeId,
            @RequestParam(value = "pageSize", required = false) Integer pageSize)
    {
        List<BizConsultMessage> rows = bizVetOnlineConsultService.selectSessionMessages(sessionId, beforeId, pageSize,
                SecurityUtils.getUserId());
        return success(rows);
    }

    @PreAuthorize("@ss.hasPermi('diseaseTreatment:vetOnlineConsult:send')")
    @Log(title = "在线接诊（兽医）发送消息", businessType = BusinessType.INSERT)
    @PostMapping("/session/{sessionId}/message")
    public AjaxResult send(@PathVariable("sessionId") Long sessionId, @RequestBody VetConsultSendBody body)
    {
        BizConsultMessage message = bizVetOnlineConsultService.sendVetMessage(sessionId, body,
                SecurityUtils.getUserId(), SecurityUtils.getUsername());
        return success(message);
    }
}
