package cn.iocoder.yudao.module.chain.controller.admin.operatedetail;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.chain.controller.admin.operatedetail.vo.OperateDetailPageReqVO;
import cn.iocoder.yudao.module.chain.controller.admin.operatedetail.vo.OperateDetailRespVO;
import cn.iocoder.yudao.module.chain.convert.operatedetail.OperateDetailConvert;
import cn.iocoder.yudao.module.chain.dal.dataobject.operatedetail.OperateDetailDO;
import cn.iocoder.yudao.module.chain.service.operatedetail.OperateDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 区块上链操作具体上链信息")
@RestController
@RequestMapping("/chain/operate-detail")
@Validated
public class OperateDetailController {

    @Resource
    private OperateDetailService operateDetailService;

    @DeleteMapping("/delete")
    @ApiOperation("删除区块上链操作具体上链信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('chain:operate-detail:delete')")
    public CommonResult<Boolean> deleteOperateDetail(@RequestParam("id") Long id) {
        operateDetailService.deleteOperateDetail(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得区块上链操作具体上链信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('chain:operate-detail:query')")
    public CommonResult<OperateDetailRespVO> getOperateDetail(@RequestParam("id") Long id) {
        OperateDetailDO operateDetail = operateDetailService.getOperateDetail(id);
        return success(OperateDetailConvert.INSTANCE.convert(operateDetail));
    }

    @GetMapping("/list")
    @ApiOperation("获得区块上链操作具体上链信息列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('chain:operate-detail:query')")
    public CommonResult<List<OperateDetailRespVO>> getOperateDetailList(@RequestParam("ids") Collection<Long> ids) {
        List<OperateDetailDO> list = operateDetailService.getOperateDetailList(ids);
        return success(OperateDetailConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得区块上链操作具体上链信息分页")
    @PreAuthorize("@ss.hasPermission('chain:operate-detail:query')")
    public CommonResult<PageResult<OperateDetailRespVO>> getOperateDetailPage(@Valid OperateDetailPageReqVO pageVO) {
        PageResult<OperateDetailDO> pageResult = operateDetailService.getOperateDetailPage(pageVO);
        return success(OperateDetailConvert.INSTANCE.convertPage(pageResult));
    }

}
