package cc.iotkit.manager.controller;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request;
import cc.iotkit.manager.config.BeanUtils;

import cc.iotkit.manager.dto.bo.device.DeviceInfoBo;
import cc.iotkit.manager.dto.bo.taskinfo.TaskInfoBo;
import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordListSaveReqVO;
import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordPageReqVO;
import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordRespVO;
import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordSaveReqVO;
import cc.iotkit.manager.service.DIccidRecordService;
import cc.iotkit.model.iccid.DIccidRecordDO;
import cn.hutool.db.PageResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.Parameter;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

import java.util.List;

import static cc.iotkit.common.api.Response.success;

@Api(tags = {"物联网iccid管理"})
@Slf4j
@RestController
@RequestMapping("/dIccidRecord")
public class IccidRecordController {


  @Resource
    private DIccidRecordService dIccidRecordService;

    @PostMapping("/add")
 //   @Operation(summary = "录入物联网卡")
 //   @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:create')")
    public String createDIccidRecord(@Valid @RequestBody Request<DIccidRecordSaveReqVO> createReqVO) {
        return dIccidRecordService.createDIccidRecord(createReqVO.getData());
    }
    @PostMapping("/createList")
   // @Operation(summary = "批量录入物联网卡")
  //  @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:create')")
    public String createList(@Valid @RequestBody Request<DIccidRecordListSaveReqVO> createReqVO
    ) {
        Integer num =createReqVO.getData().getEndIccid()-createReqVO.getData().getStartIccid();
        return dIccidRecordService.createList(createReqVO.getData(),num);
    }

    @PostMapping("/edit")
   // @Operation(summary = "更新物联网卡")
   // @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:update')")
    public Boolean updateDIccidRecord(@Valid @RequestBody Request<DIccidRecordSaveReqVO> updateReqVO) {
        dIccidRecordService.updateDIccidRecord(updateReqVO.getData());
        return true;
    }

    @PostMapping("/delete")
   // @Operation(summary = "删除物联网卡")
   // @Parameter(name = "id", description = "编号", required = true)
   // @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:delete')")
    public Boolean deleteDIccidRecord(@Validated @RequestBody Request<Long> request) {
        dIccidRecordService.deleteDIccidRecord(request.getData());
        return true;
    }

    @PostMapping("/getDetail")
   // @Operation(summary = "获得物联网卡")
  //  @Parameter(name = "id", description = "编号", required = true, example = "1024")
  //  @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:query')")
    public DIccidRecordDO getDIccidRecord(@Validated @RequestBody Request<Long> request) {
        DIccidRecordDO dIccidRecord = dIccidRecordService.getDIccidRecord(request.getData());
        return dIccidRecord;
    }

    @PostMapping("/list")
   // @Operation(summary = "获得物联网卡分页")
    public Paging<DIccidRecordRespVO> getDIccidRecordPage( @Validated @RequestBody  PageRequest<DIccidRecordPageReqVO> pageReqVO) {
        Paging<DIccidRecordRespVO> pageResult = dIccidRecordService.getDIccidRecordPage(pageReqVO);

        return  pageResult;
    }



}
