
package com.tmerclub.cloud.im.controller.multishop;


import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.common.util.BeanUtil;
import com.tmerclub.cloud.im.dto.ImMsgBizSkillsDTO;
import com.tmerclub.cloud.im.service.ImMsgBizSkillsService;
import com.tmerclub.cloud.im.vo.ImMsgBizSkillsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 客服自动回复表
 *
 * @author tmerclub
 * @date 2023-03-23 17:43:40
 */
@RestController("multishopImMsgBizSkillsController")
@RequestMapping("/m/imMsgBizSkills")
@Tag(name = "店铺自动回复接口")
public class ImMsgBizSkillsController {

    @Autowired
    private ImMsgBizSkillsService imMsgBizSkillsService;


    @GetMapping("/page")
    @Operation(summary = "获取客服自动回复表列表", description = "分页获取客服自动回复表列表")
    public ServerResponseEntity<PageVO<ImMsgBizSkillsVO>> page(@Valid PageDTO pageDTO, ImMsgBizSkillsDTO imMsgBizSkillsDTO) {
        Long shopId = AuthUserContext.get().getTenantId();
        PageVO<ImMsgBizSkillsVO> imMsgBizSkillsPage = imMsgBizSkillsService.page(pageDTO, imMsgBizSkillsDTO, shopId);
        return ServerResponseEntity.success(imMsgBizSkillsPage);
    }

    @GetMapping
    @Operation(summary = "获取客服自动回复表", description = "根据id获取客服自动回复表")
    public ServerResponseEntity<ImMsgBizSkillsVO> getById(@RequestParam Long id) {
        return ServerResponseEntity.success(imMsgBizSkillsService.getById(id));
    }

    @PostMapping
    @Operation(summary = "保存客服自动回复表", description = "保存客服自动回复表")
    public ServerResponseEntity<Void> save(@Valid @RequestBody ImMsgBizSkillsDTO imMsgBizSkillsDTO) {
        ImMsgBizSkillsVO imMsgBizSkills = BeanUtil.map(imMsgBizSkillsDTO, ImMsgBizSkillsVO.class);
        imMsgBizSkills.setShopId(AuthUserContext.get().getTenantId());
        imMsgBizSkillsService.save(imMsgBizSkills);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新客服自动回复表", description = "更新客服自动回复表")
    public ServerResponseEntity<Void> update(@Valid @RequestBody ImMsgBizSkillsDTO imMsgBizSkillsDTO) {
        ImMsgBizSkillsVO imMsgBizSkills = BeanUtil.map(imMsgBizSkillsDTO, ImMsgBizSkillsVO.class);
        imMsgBizSkillsService.update(imMsgBizSkills);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除客服自动回复表", description = "根据客服自动回复表id删除客服自动回复表")
    public ServerResponseEntity<Void> delete(@RequestParam Long id) {
        imMsgBizSkillsService.deleteById(id);
        return ServerResponseEntity.success();
    }
}
