import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

public class DynamicDiffusionConfig {
    private Map<String, WeaponDiffusionConfig> weaponConfigMap;

    public DynamicDiffusionConfig() {
        this.weaponConfigMap = new HashMap<>();
    }

    public void addWeaponConfig(WeaponDiffusionConfig config) {
        if (config != null && config.getUniqueKey() != null) {
            weaponConfigMap.put(config.getUniqueKey(), config);
        }
    }

    public WeaponDiffusionConfig getWeaponConfig(String uniqueKey) {
        return weaponConfigMap.getOrDefault(uniqueKey, null);
    }

    public Map<String, WeaponDiffusionConfig> getWeaponConfigMap() {
        return weaponConfigMap;
    }
}

public class WeaponDiffusionConfig {
    private String uniqueKey;
    private List<DiffusionParameter> parameters;

    public WeaponDiffusionConfig(String categoryPath) {
        this.uniqueKey = categoryPath;
        this.parameters = new ArrayList<>();
    }

    public WeaponDiffusionConfig(String modelName, String dataTag) {
        this.uniqueKey = modelName + "_" + dataTag;
        this.parameters = new ArrayList<>();
    }

    public void addParameter(DiffusionParameter param) {
        if (param == null || param.getKey() == null) return;
        for (int i = 0; i < parameters.size(); i++) {
            if (parameters.get(i).getKey().equals(param.getKey())) {
                parameters.set(i, param);
                return;
            }
        }
        parameters.add(param);
    }

    public DiffusionParameter getParameter(String key) {
        for (DiffusionParameter param : parameters) {
            if (param.getKey().equals(key)) {
                return param;
            }
        }
        return null;
    }

    public String getUniqueKey() {
        return uniqueKey;
    }

    public List<DiffusionParameter> getParameters() {
        return parameters;
    }
}

public class DiffusionParameter {
    private String key;
    private String value;
    private String dataTag;

    public DiffusionParameter(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public DiffusionParameter(String key, String value, String dataTag) {
        this.key = key;
        this.value = value;
        this.dataTag = dataTag;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getDataTag() {
        return dataTag;
    }
}

public class DiffusionConfigInitializer {
    public static DynamicDiffusionConfig initConfig() {
        DynamicDiffusionConfig config = new DynamicDiffusionConfig();

        WeaponDiffusionConfig assaultRifleConfig = new WeaponDiffusionConfig("/Script/Engine.Weapon.AssaultRifle");
        assaultRifleConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingAssaultRifle.ContinuousFire.HitEnemy",
                "Head"
        ));
        assaultRifleConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.AssaultRifle.ContinuousFire.HitEnemyHead.Probability",
                "99%"
        ));
        assaultRifleConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingAssaultRifle.ContinuousFire.MaxValue",
                "0.072",
                "data1"
        ));
        assaultRifleConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingAssaultRifle.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(assaultRifleConfig);

        WeaponDiffusionConfig smgConfig = new WeaponDiffusionConfig("/Script/Engine.Weapon.SubmachineGun");
        smgConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingSubmachineGun.ContinuousFire.HitEnemy",
                "Head"
        ));
        smgConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.SubmachineGun.ContinuousFire.HitEnemyHead.Probability",
                "99%"
        ));
        smgConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingSubmachineGun.ContinuousFire.MaxValue",
                "0.072",
                "data2"
        ));
        smgConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingSubmachineGun.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(smgConfig);

        WeaponDiffusionConfig lmgConfig = new WeaponDiffusionConfig("/Script/Engine.Weapon.LightMachineGun");
        lmgConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingLightMachineGun.ContinuousFire.HitEnemy",
                "Head"
        ));
        lmgConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.LightMachineGun.ContinuousFire.HitEnemyHead.Probability",
                "99%"
        ));
        lmgConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingLightMachineGun.ContinuousFire.MaxValue",
                "0.072",
                "data3"
        ));
        lmgConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingLightMachineGun.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(lmgConfig);

        WeaponDiffusionConfig m416Config = new WeaponDiffusionConfig("M416AssaultRifle", "data1");
        m416Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingM416AssaultRifle.ContinuousFire.MaxValue",
                ""
        ));
        m416Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingM416AssaultRifle.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(m416Config);

        WeaponDiffusionConfig akmConfig = new WeaponDiffusionConfig("AKMAssaultRifles", "data1");
        akmConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingAKMAssaultRifles.ContinuousFire.MaxValue",
                ""
        ));
        akmConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingAKMAssaultRifles.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(akmConfig);

        WeaponDiffusionConfig augConfig = new WeaponDiffusionConfig("AUGAssaultRifle", "data1");
        augConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingAUGAssaultRifle.ContinuousFire.MaxValue",
                ""
        ));
        augConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingAUGAssaultRifle.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(augConfig);

        WeaponDiffusionConfig m762Config = new WeaponDiffusionConfig("M762AssaultRifle", "data1");
        m762Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingM762AssaultRifle.ContinuousFire.MaxValue",
                ""
        ));
        m762Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingM762AssaultRifle.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(m762Config);

        WeaponDiffusionConfig sacrlConfig = new WeaponDiffusionConfig("SACR-LAssaultRifle", "data1");
        sacrlConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingSACR-LAssaultRifle.ContinuousFire.MaxValue",
                ""
        ));
        sacrlConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingSACR-LAssaultRifle.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(sacrlConfig);

        WeaponDiffusionConfig p90Config = new WeaponDiffusionConfig("P90SubmachineGun", "data2");
        p90Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingP90SubmachineGun.ContinuousFire.MaxValue",
                ""
        ));
        p90Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingP90SubmachineGun.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(p90Config);

        WeaponDiffusionConfig uziConfig = new WeaponDiffusionConfig("UZISubmachineGun", "data2");
        uziConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingUZISubmachineGun.ContinuousFire.MaxValue",
                ""
        ));
        uziConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingUZISubmachineGun.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(uziConfig);

        WeaponDiffusionConfig ump45Config = new WeaponDiffusionConfig("UMP45SubmachineGun", "data2");
        ump45Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingUMP45SubmachineGun.ContinuousFire.MaxValue",
                ""
        ));
        ump45Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingUMP45SubmachineGun.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(ump45Config);

        WeaponDiffusionConfig vectorConfig = new WeaponDiffusionConfig("VectorSubmachineGun", "data2");
        vectorConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingVectorSubmachineGun.ContinuousFire.MaxValue",
                ""
        ));
        vectorConfig.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingVectorSubmachineGun.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(vectorConfig);

        WeaponDiffusionConfig mg3Config = new WeaponDiffusionConfig("MG3LightMachineGun", "data3");
        mg3Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingMG3LightMachineGun.ContinuousFire.MaxValue",
                ""
        ));
        mg3Config.addParameter(new DiffusionParameter(
                "BulletDiffusion@Player.Character.HoldingMG3LightMachineGun.ContinuousFire.HitArea",
                "999"
        ));
        config.addWeaponConfig(mg3Config);

        return config;
    }

    public static void main(String[] args) {
        DynamicDiffusionConfig diffusionConfig = initConfig();
        for (WeaponDiffusionConfig weaponConfig : diffusionConfig.getWeaponConfigMap().values()) {
            if (weaponConfig.getUniqueKey().startsWith("/Script/")) {
                System.out.println("=== " + weaponConfig.getUniqueKey() + " ===");
            } else {
                System.out.println("=== " + weaponConfig.getUniqueKey() + " ===");
            }
            for (DiffusionParameter param : weaponConfig.getParameters()) {
                String dataTagInfo = param.getDataTag() != null ? " [DataTag: " + param.getDataTag() + "]" : "";
                System.out.println(param.getKey() + " | " + param.getValue() + dataTagInfo);
            }
            System.out.println("----------------------------------------");
        }
    }
}