package com.ads.business.controller;

import com.ads.business.service.ConversationService;
import com.ads.business.service.model.request.*;
import com.ads.business.service.model.response.ConversationDetail;
import com.ads.business.service.model.response.ConversationDropListResponse;
import com.ads.business.service.model.response.ConversationListResponse;
import com.ads.common.data.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Description: 会话管理
 * @Author: JJC
 * @Date: 2021/11/18  18:01
 */
@Api(tags = "会话管理")
@RestController
@RequestMapping("/conversation")
public class ConversationController {

    @Resource
    private ConversationService conversationService;


    @PostMapping("/create")
    @ApiOperation("创建群会话")
    JsonResult create(@RequestBody @Valid ConversationAddRequest request) {
        return conversationService.create(request);
    }

    @GetMapping("/list")
    @ApiOperation(value = "会话列表", response = ConversationListResponse.class)
    public JsonResult list(ConversationListRequest request) {
        return conversationService.selectList(request);
    }

    @GetMapping("/detail/{chatId}")
    @ApiOperation(value = "会话详情", response = ConversationDetail.class)
    public JsonResult detail(@PathVariable String chatId) {
        return conversationService.detail(chatId);
    }

    @PutMapping("/{chatId}")
    @ApiOperation(value = "同步会话")
    public JsonResult sync(@PathVariable String chatId) {
        return conversationService.sync(chatId);
    }


    @PutMapping("/batch/sync")
    @ApiOperation(value = "一键同步会话")
    public JsonResult batchSync(String conversationName, String ownerName) {
        return conversationService.batchSync(conversationName, ownerName);
    }

    @GetMapping("/getDropList")
    @ApiOperation(value = "会话下拉列表", response = ConversationDropListResponse.class)
    public JsonResult getDropList() {
        return JsonResult.success(conversationService.getDropList());
    }
}
