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

import com.jeesharp.business.modules.mall.application.MallGiftRuleApplicationService;
import com.jeesharp.business.modules.mall.entity.MallGiftRule;
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.util.List;
import java.util.Map;

/**
 * 赠品规则移动端 Controller
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/mall/gift/v1")
@Tag(name = "赠品")
@AllArgsConstructor
public class MallGiftRuleMobileController {

    private final MallGiftRuleApplicationService giftRuleApplicationService;

    @Operation(summary = "获取SKU可用的赠品")
    @PostMapping(value = "skuGifts")
    public AjaxResult<List<MallGiftRule>> getSkuGifts(@RequestParam("skuId") String skuId) {
        List<MallGiftRule> gifts = giftRuleApplicationService.getGiftRulesBySku(skuId);
        return AjaxResult.okData(gifts);
    }

    @Operation(summary = "检查订单满件赠品")
    @PostMapping(value = "checkFullItemGifts")
    public AjaxResult<List<MallGiftRule>> checkFullItemGifts(@RequestBody Map<String, Integer> skuQuantities) {
        List<MallGiftRule> gifts = giftRuleApplicationService.checkFullItemGifts(skuQuantities);
        return AjaxResult.okData(gifts);
    }
}