package com.github.material.monitor.demo.mock;

import com.github.material.monitor.MaterialStyle;

import java.util.UUID;

/**
 * 构造带网关必填字段的 {@link MockAdInfo}（对接文档 meta.ad_info / event_info）。
 *
 * <p>正式接入直接使用广告 SDK {@code onAdShow} 等回调中的 {@code ATAdInfo}，无需本工厂。</p>
 */
public final class MockAdInfoFactory {

    private static final String DEMO_AD_SOURCE_ID = "src_demo_001";
    private static final int DEMO_NETWORK_FIRM_ID = 10;
    private static final double DEMO_ECPM = 12.5;

    private MockAdInfoFactory() {
    }

    public static MockAdInfo forStyle(MaterialStyle style) {
        return forStyle(style, placementIdForStyle(style));
    }

    public static String demoAdSourceId() {
        return DEMO_AD_SOURCE_ID;
    }

    public static int demoNetworkFirmId() {
        return DEMO_NETWORK_FIRM_ID;
    }

    public static double demoEcpm() {
        return DEMO_ECPM;
    }

    public static MockAdInfo forStyle(MaterialStyle style, String placementId) {
        String showId = UUID.randomUUID().toString();
        String requestId = "req_" + showId.replace("-", "").substring(0, 16);
        String creativeId = "cr_demo_" + style.getFolderName();
        return new MockAdInfo(
                placementId,
                showId,
                formatForStyle(style),
                DEMO_AD_SOURCE_ID,
                DEMO_NETWORK_FIRM_ID,
                adTypeForStyle(style),
                DEMO_ECPM,
                requestId,
                creativeId
        );
    }

    public static String placementIdForStyle(MaterialStyle style) {
        switch (style) {
            case BANNER:
                return "b62b01a36e4572";
            case INTERSTITIAL:
                return "b62b028b61c800";
            case REWARDED_VIDEO:
                return "b62ecb800e1f84";
            case NATIVE:
                return "b6305efb12d408";
            case SPLASH:
            default:
                return "b62b0272f8762f";
        }
    }

    static String formatForStyle(MaterialStyle style) {
        switch (style) {
            case BANNER:
                return "Banner";
            case INTERSTITIAL:
                return "Interstitial";
            case REWARDED_VIDEO:
                return "RewardedVideo";
            case NATIVE:
                return "Native";
            case SPLASH:
            default:
                return "Splash";
        }
    }

    /** 网关 ad_type：1 开屏、2 插屏、3 激励、4 原生（Banner Demo 暂映射为 4） */
    public static int adTypeForStyle(MaterialStyle style) {
        switch (style) {
            case INTERSTITIAL:
                return 2;
            case REWARDED_VIDEO:
                return 3;
            case NATIVE:
            case BANNER:
                return 4;
            case SPLASH:
            default:
                return 1;
        }
    }
}
