package org.dromara.main.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.entity.UploadResult;
import org.dromara.common.oss.factory.OssFactory;
import org.dromara.common.web.core.BaseController;
import org.dromara.main.domain.bo.CsSeatConfigBo;
import org.dromara.main.domain.vo.CsSeatConfigVo;
import org.dromara.main.service.ICsSeatConfigService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/main/seat")
public class CsSeatConfigController extends BaseController {

    private final ICsSeatConfigService seatConfigService;

    /**
     * 查询坐席配置列表
     */
    @SaCheckPermission("main:seat:list")
    @GetMapping("/list")
    public TableDataInfo<CsSeatConfigVo> list(CsSeatConfigBo bo, PageQuery pageQuery) {
        return seatConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取坐席配置详细信息
     */
    @SaCheckPermission("main:seat:query")
    @GetMapping("/{id}")
    public R<CsSeatConfigVo> getInfo(@PathVariable Long id) {
        return R.ok(seatConfigService.queryById(id));
    }

    /**
     * 新增坐席配置
     */
    @SaCheckPermission("main:seat:add")
    @Log(title = "坐席配置", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CsSeatConfigBo bo) {
        return toAjax(seatConfigService.insertByBo(bo));
    }

    /**
     * 修改坐席配置
     */
    @SaCheckPermission("main:seat:edit")
    @Log(title = "坐席配置", businessType = BusinessType.UPDATE)
    @PutMapping("/{id}")
    public R<Void> edit(@PathVariable Long id,
                        @Validated(EditGroup.class) @RequestBody CsSeatConfigBo bo) {
        bo.setId(id);
        return toAjax(seatConfigService.updateByBo(bo));
    }

    /**
     * 删除坐席配置
     */
    @SaCheckPermission("main:seat:remove")
    @Log(title = "坐席配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable List<Long> ids) {
        return toAjax(seatConfigService.deleteByIds(ids));
    }

    /**
     * 修改坐席状态
     */
    @SaCheckPermission("main:seat:edit")
    @Log(title = "修改坐席状态", businessType = BusinessType.UPDATE)
    @PutMapping("/{id}/status")
    public R<Void> changeStatus(@PathVariable Long id, @RequestBody Map<String, Integer> params) {
        return toAjax(seatConfigService.changeStatus(id, params.get("status")));
    }

}
