package cn.iocoder.yudao.module.system.controller.admin.discount;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.controller.admin.discount.vo.DiscountRulePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.discount.vo.DiscountRuleRespVO;
import cn.iocoder.yudao.module.system.controller.admin.discount.vo.DiscountRuleSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.discount.DiscountRuleDO;
import cn.iocoder.yudao.module.system.service.discount.DiscountRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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.List;

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


@Tag(name = "管理后台 - 长者优惠规则")
@RestController
@RequestMapping("/elderly/discountRule")
@Validated
public class DiscountRuleController {

    @Resource
    private DiscountRuleService discountRuleService;


    @PostMapping("/create")
    @Operation(summary = "创建长者优惠规则")
    @TenantIgnore
    public CommonResult<Boolean> createDiscountRule(@Valid @RequestBody List<DiscountRuleSaveReqVO> createReqVO) {
        discountRuleService.createDiscountRule(createReqVO);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新长者优惠规则")
    @TenantIgnore
    public CommonResult<Boolean> updateDiscountRule(@Valid @RequestBody DiscountRuleSaveReqVO updateReqVO) {
        discountRuleService.updateDiscountRule(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除长者优惠规则")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> deleteDiscountRule(@RequestParam("id") Long id) {
        discountRuleService.deleteDiscountRule(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得长者优惠规则")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<DiscountRuleRespVO> getDiscountRule(@RequestParam("id") Long id) {
        DiscountRuleDO discountRule = discountRuleService.getDiscountRule(id);
        return success(BeanUtils.toBean(discountRule, DiscountRuleRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得长者优惠规则分页")
    @TenantIgnore
    public CommonResult<PageResult<DiscountRuleRespVO>> getDiscountRulePage(@Valid DiscountRulePageReqVO pageVO) {
        PageResult<DiscountRuleDO> pageResult = discountRuleService.getDiscountRulePage(pageVO);
        return success(BeanUtils.toBean(pageResult, DiscountRuleRespVO.class));
    }

//    @GetMapping("/list")
//    @Operation(summary = "获得长者优惠规则列表")
//    @Parameter(name = "ids", description = "编号列表", required = true)
//    @TenantIgnore
//    public CommonResult<List<DiscountRuleRespVO>> getDiscountRuleList(@RequestParam("ids") List<Long> ids) {
//        List<DiscountRuleDO> list = discountRuleService.getDiscountRuleList(ids);
//        return success(BeanUtils.toBean(list, DiscountRuleRespVO.class));
//    }

    @GetMapping("/getDiscountRuleListByElderId")
    @Operation(summary = "根据长者ID获取优惠规则列表")
    @Parameter(name = "elderId", description = "长者ID", required = true)
    @TenantIgnore
    public CommonResult<List<DiscountRuleRespVO>> getDiscountRuleListByElderId(@RequestParam("elderId") Long elderId) {
        List<DiscountRuleDO> list = discountRuleService.getDiscountRuleListByElderId(elderId);
        return success(BeanUtils.toBean(list, DiscountRuleRespVO.class));
    }

}