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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberCardChangePageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberCardConsumptionPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberCardConsumptionDO;
import cn.iocoder.yudao.module.member.service.user.MemberCardConsumptionService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.Objects;

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

@Tag(name = "管理后台 - 会员卡消费")
@RestController
@RequestMapping("/member/card-consumption")
@Validated
public class MemberCardConsumptionController {

    @Resource
    private MemberCardConsumptionService cardConsumptionService;

    @PostMapping("/create")
    @Operation(summary = "创建会员卡消费")
    public CommonResult<Long> createMemberCardConsumption(@Valid @RequestBody MemberCardConsumptionDO createReqVO) {
        return success(cardConsumptionService.createMemberCardConsumption(createReqVO));
    }

    @PutMapping("/cancel")
    @Operation(summary = "取消会员卡消费")
    public CommonResult<Boolean> cancel( @RequestBody MemberCardConsumptionDO updateReqVO) {
        cardConsumptionService.cancel(updateReqVO);
        return success(true);
    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除会员卡消费")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('member:card-consumption:delete')")
//    public CommonResult<Boolean> deleteCardConsumption(@RequestParam("id") Long id) {
//        cardConsumptionService.deleteCardConsumption(id);
//        return success(true);
//    }
//
    @GetMapping("/get")
    @Operation(summary = "获得会员卡消费")
    public CommonResult<MemberCardConsumptionDO> getCardConsumption(@RequestParam("id") Long id) {
        return success(cardConsumptionService.getCardConsumption(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得会员卡消费分页")
    @TenantIgnore
    public CommonResult<PageResult<MemberCardConsumptionDO>> getCardConsumptionPage(@Valid MemberCardConsumptionPageReqVO pageReqVO) {
        pageReqVO.setTenantId(Objects.isNull(pageReqVO.getTenantId()) ? TenantContextHolder.getTenantId() : pageReqVO.getTenantId());
        PageResult<MemberCardConsumptionDO> pageResult = cardConsumptionService.getCardConsumptionPage(pageReqVO);
        return success(pageResult);
    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出会员卡消费 Excel")
//    @PreAuthorize("@ss.hasPermission('member:card-consumption:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportCardConsumptionExcel(@Valid CardConsumptionPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<CardConsumptionDO> list = cardConsumptionService.getCardConsumptionPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "会员卡消费.xls", "数据", CardConsumptionRespVO.class,
//                        BeanUtils.toBean(list, CardConsumptionRespVO.class));
//    }

}