package com.fs.store.strategy;

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

/**
 * 指定包邮装饰器
 */
public class FreeShippingDecorator implements ShippingFeeDecorator {
    private final List<FreeShippingRule> freeShippingRules;

    public FreeShippingDecorator(List<FreeShippingRule> freeShippingRules) {
        this.freeShippingRules = freeShippingRules;
    }

    @Override
    public BigDecimal calculateFee(BigDecimal baseFee, ShippingOrder order, Region region) {
        // 检查是否有适用的包邮规则
        for (FreeShippingRule rule : freeShippingRules) {
            if (rule.getRegion().equals(region.getCityId()) &&
                    (order.getWeight().compareTo(rule.getMinWeight()) <= 0)) {
                return BigDecimal.ZERO;
            }
        }
        return baseFee;
    }
}
