package com.usky.vpp.util;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 竞价配置工具
 */
public final class VppBiddingConfigHelper {

    public static final int BIDDING_MODE_TIME_SLOT = 1;
    public static final int BIDDING_MODE_WHOLE = 2;

    private static final DateTimeFormatter PERIOD_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    private VppBiddingConfigHelper() {
    }

    public static String resolveBiddingModeName(Integer biddingMode) {
        if (biddingMode == null) {
            return null;
        }
        switch (biddingMode) {
            case BIDDING_MODE_TIME_SLOT:
                return "分时段竞价";
            case BIDDING_MODE_WHOLE:
                return "整体竞价";
            default:
                return "未知模式";
        }
    }

    public static String resolveAdvanceCloseHoursLabel(Integer advanceCloseHours) {
        if (advanceCloseHours == null) {
            return null;
        }
        return ">" + advanceCloseHours;
    }

    public static String formatEffectivePeriod(LocalDateTime start, LocalDateTime end) {
        if (start == null || end == null) {
            return null;
        }
        return PERIOD_FMT.format(start) + " - " + PERIOD_FMT.format(end);
    }

    public static void validatePriceRange(BigDecimal minPrice, BigDecimal maxPrice) {
        if (minPrice == null || maxPrice == null) {
            return;
        }
        if (minPrice.compareTo(maxPrice) > 0) {
            throw new com.usky.common.core.exception.BusinessException("最低价格不能高于最高价格");
        }
    }
}
