package cn.iocoder.yudao.module.member.controller.admin.wxstoreorderdetail;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.member.controller.admin.wxstoreorderdetail.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.wxstoreorderdetail.WxStoreOrderDetailDO;
import cn.iocoder.yudao.module.member.service.wxstoreorderdetail.WxStoreOrderDetailService;

@Tag(name = "管理后台 - 微信付款码订单详情")
@RestController
@RequestMapping("/member/wx-store-order-detail")
@Validated
public class WxStoreOrderDetailController {

    @Resource
    private WxStoreOrderDetailService wxStoreOrderDetailService;

    @PostMapping("/create")
    @Operation(summary = "创建微信付款码订单详情")
    @PreAuthorize("@ss.hasPermission('member:wx-store-order-detail:create')")
    public CommonResult<Long> createWxStoreOrderDetail(@Valid @RequestBody WxStoreOrderDetailSaveReqVO createReqVO) {
        return success(wxStoreOrderDetailService.createWxStoreOrderDetail(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新微信付款码订单详情")
    @PreAuthorize("@ss.hasPermission('member:wx-store-order-detail:update')")
    public CommonResult<Boolean> updateWxStoreOrderDetail(@Valid @RequestBody WxStoreOrderDetailSaveReqVO updateReqVO) {
        wxStoreOrderDetailService.updateWxStoreOrderDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除微信付款码订单详情")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('member:wx-store-order-detail:delete')")
    public CommonResult<Boolean> deleteWxStoreOrderDetail(@RequestParam("id") Long id) {
        wxStoreOrderDetailService.deleteWxStoreOrderDetail(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得微信付款码订单详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('member:wx-store-order-detail:query')")
    public CommonResult<WxStoreOrderDetailRespVO> getWxStoreOrderDetail(@RequestParam("id") Long id) {
        WxStoreOrderDetailDO wxStoreOrderDetail = wxStoreOrderDetailService.getWxStoreOrderDetail(id);
        return success(BeanUtils.toBean(wxStoreOrderDetail, WxStoreOrderDetailRespVO.class));
    }

    @GetMapping("/getByOrderId")
    @Operation(summary = "获得微信付款码订单详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<List<WxStoreOrderDetailRespVO>> getWxStoreOrderDetailByOrderId(@RequestParam("orderId") Long orderId) {
        List<WxStoreOrderDetailDO> wxStoreOrderDetailByOrderId = wxStoreOrderDetailService.getWxStoreOrderDetailByOrderId(orderId);
        return success(BeanUtils.toBean(wxStoreOrderDetailByOrderId, WxStoreOrderDetailRespVO.class));
    }


    @GetMapping("/page")
    @Operation(summary = "获得微信付款码订单详情分页")
    @PreAuthorize("@ss.hasPermission('member:wx-store-order-detail:query')")
    public CommonResult<PageResult<WxStoreOrderDetailRespVO>> getWxStoreOrderDetailPage(@Valid WxStoreOrderDetailPageReqVO pageReqVO) {
        PageResult<WxStoreOrderDetailDO> pageResult = wxStoreOrderDetailService.getWxStoreOrderDetailPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WxStoreOrderDetailRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出微信付款码订单详情 Excel")
    @PreAuthorize("@ss.hasPermission('member:wx-store-order-detail:export')")
    @OperateLog(type = EXPORT)
    public void exportWxStoreOrderDetailExcel(@Valid WxStoreOrderDetailPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WxStoreOrderDetailDO> list = wxStoreOrderDetailService.getWxStoreOrderDetailPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "微信付款码订单详情.xls", "数据", WxStoreOrderDetailRespVO.class,
                        BeanUtils.toBean(list, WxStoreOrderDetailRespVO.class));
    }

}