package com.tzld.piaoquan.api.controller.wecom.thirdpart;

import com.tzld.piaoquan.api.model.param.wecom.thirdpart.ThirdPartyRoomConfigParam;
import com.tzld.piaoquan.api.model.param.wecom.thirdpart.ThirdPartyConfigGetParam;
import com.tzld.piaoquan.api.model.param.wecom.thirdpart.ThirdPartyRoomListParam;
import com.tzld.piaoquan.api.model.vo.IdNameVO;
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyRoomConfigVO;
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyRoomVO;
import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyRoomService;
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
import com.tzld.piaoquan.growth.common.utils.page.Page;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/wecom/thirdparty/room")
@CrossOrigin(origins = "*")
public class WeComThirdPartyRoomController {

    @Autowired
    private WeComThirdPartyRoomService service;

    @ApiOperation(value = "群列表")
    @PostMapping("/list")
    public CommonResponse<Page<ThirdPartyRoomVO>> list(@RequestBody ThirdPartyRoomListParam param) {
        return CommonResponse.success(service.list(param));
    }

    @ApiOperation(value = "获取推送人员列表")
    @GetMapping("/getPushAccountList")
    public CommonResponse<List<IdNameVO<Long>>> getPushAccountList(@RequestParam Long roomId, @RequestParam(required = false) String name) {
        return CommonResponse.success(service.getPushAccountList(roomId, name));
    }

    @ApiOperation(value = "获取群配置")
    @PostMapping("/getRoomConfig")
    public CommonResponse<ThirdPartyRoomConfigVO> getRoomConfig(@RequestBody ThirdPartyConfigGetParam param) {
        return CommonResponse.success(service.getRoomConfig(param));
    }

    @ApiOperation(value = "保存群配置")
    @PostMapping("/saveRoomConfig")
    public CommonResponse<Void> saveRoomConfig(@RequestBody ThirdPartyRoomConfigParam param) {
        service.saveRoomConfig(param, null);
        return CommonResponse.success();
    }
}
