package cn.hanghui.outapi.platform.tenant.controller;

import cn.hanghui.outapi.platform.common.config.log.Log;
import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
import cn.hanghui.outapi.platform.tenant.entity.dto.auth.OpenInterfaceAuthDeviceDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.auth.OpenInterfaceAuthDeviceImportDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.auth.OpenInterfaceAuthDevicePageDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.auth.OpenInterfaceAuthDeviceVo;
import cn.hanghui.outapi.platform.tenant.entity.enums.BusinessTypeEnum;
import cn.hanghui.outapi.platform.tenant.entity.enums.LogTagEnum;
import cn.hanghui.outapi.platform.tenant.service.OpenInterfaceAuthDeviceService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

/**
 * @author shisl
 * @package cn.hanghui.outapi.platform.tenant.controller
 * @class OpenInterfaceAuthDeviceController
 * @date 2024/1/17 下午1:24
 * @description
 */
@Api(tags = "三方api设备授权管理")
@RestController
@RequestMapping("/api/v1/open/auth/device")
public class OpenInterfaceAuthDeviceController {

    @Autowired
    private OpenInterfaceAuthDeviceService openInterfaceAuthDeviceService;


    @ApiOperation(value = "添加/编辑")
    @PostMapping("/add")
    @Log(tag = LogTagEnum.THIRD_API,title = "添加/编辑设备",businessTypeEnum = BusinessTypeEnum.INSERT_UPDATE)
    public RestResult<Boolean> add(@RequestBody OpenInterfaceAuthDeviceDto dto) {
        return openInterfaceAuthDeviceService.add(dto);
    }

    @ApiOperation(value = "批量添加")
    @PostMapping("/batch/add")
    @Log(tag = LogTagEnum.THIRD_API,title = "批量添加设备",businessTypeEnum = BusinessTypeEnum.INSERT)
    public RestResult<Boolean> batchAdd(@RequestBody OpenInterfaceAuthDeviceImportDto dto) {
        return openInterfaceAuthDeviceService.batchAdd(dto);
    }


    @ApiOperation(value = "删除")
    @GetMapping("/del/{id}")
    @Log(tag = LogTagEnum.THIRD_API,title = "删除设备",businessTypeEnum = BusinessTypeEnum.DELETE)
    public RestResult<Boolean> del(@PathVariable(value = "id") @ApiParam(value = "id", required = true) Long id) {

        return openInterfaceAuthDeviceService.del(id);
    }

    @ApiOperation(value = "授权")
    @GetMapping("/enable/{id}")
    @Log(tag = LogTagEnum.THIRD_API,title = "授权设备",businessTypeEnum = BusinessTypeEnum.AUTH)
    public RestResult<Boolean> enable(@PathVariable(value = "id") @ApiParam(value = "id", required = true) Long id) {
        return openInterfaceAuthDeviceService.updateStatus(id, Boolean.TRUE);
    }

    @ApiOperation(value = "取消授权")
    @GetMapping("/disable/{id}")
    @Log(tag = LogTagEnum.THIRD_API,title = "取消授权设备",businessTypeEnum = BusinessTypeEnum.CANCEL_AUTH)
    public RestResult<Boolean> disable(@PathVariable(value = "id") @ApiParam(value = "id", required = true) Long id) {
        return openInterfaceAuthDeviceService.updateStatus(id, Boolean.FALSE);
    }

    @ApiOperation(value = "查询列表（分页）")
    @PostMapping("/page")
    public RestResult<IPage<OpenInterfaceAuthDeviceVo>> pageApply(@RequestBody OpenInterfaceAuthDevicePageDto dto) {

        return openInterfaceAuthDeviceService.page(dto);
    }


}
