package com.jeesharp.business.modules.mall.controller;

import com.jeesharp.business.modules.mall.application.MallPromotionRuleApplicationService;
import com.jeesharp.business.modules.mall.entity.MallPromotionRule;
import com.jeesharp.framework.pojo.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 满减/满赠规则移动端 Controller
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/mall/promotion/v1")
@Tag(name = "促销优惠")
@AllArgsConstructor
public class MallPromotionRuleMobileController {

    private final MallPromotionRuleApplicationService promotionRuleApplicationService;

    @Operation(summary = "计算订单优惠")
    @PostMapping(value = "calculateDiscount")
    public AjaxResult<BigDecimal> calculateDiscount(@RequestParam("orderAmount") BigDecimal orderAmount) {
        BigDecimal discount = promotionRuleApplicationService.calculateFullReductionDiscount(orderAmount);
        return AjaxResult.okData(discount);
    }

    @Operation(summary = "获取可用赠品")
    @PostMapping(value = "availableGifts")
    public AjaxResult<List<MallPromotionRule>> getAvailableGifts(@RequestParam("orderAmount") BigDecimal orderAmount) {
        List<MallPromotionRule> gifts = promotionRuleApplicationService.getAvailableGifts(orderAmount);
        return AjaxResult.okData(gifts);
    }

    @Operation(summary = "获取所有促销规则")
    @PostMapping(value = "rules")
    public AjaxResult<Object> getPromotionRules() {
        List<MallPromotionRule> reductionRules = promotionRuleApplicationService.getAvailableFullReductionRules();
        List<MallPromotionRule> giftRules = promotionRuleApplicationService.getAvailableFullGiftRules();

        return AjaxResult.okData(new Object() {
            public final List<MallPromotionRule> fullReduction = reductionRules;
            public final List<MallPromotionRule> fullGift = giftRules;
        });
    }
}