{
  num: -21012,
  accuracy: true,
  basePower: 200,
  category: "Special",
  isNonstandard: "Past",
  name: "Universe Expansion",
  pp: 1,
  priority: 0,
  flags: { protect: 1, mirror: 1 },
  isZ: "astralmemoryz",

  onAfterMoveSecondarySelf(source, target, move) {
    if (!source || source.fainted) return;
    if (source.volatiles?.universeexpansiontransformed) return;

    const speciesid = (source.species?.id || "").toString().toLowerCase();
    const speciesname = (source.species?.name || "").toString().toLowerCase().replace(/[^a-z0-9]/g, "");

    const validForms = [
      "terapagosatom",
      "terapagosatomcosmic",
      "terapagosatomgalactic"
    ];

    if (!validForms.includes(speciesid) && !validForms.includes(speciesname)) return;

    const cosmic = this.dex.species.get("Terapagosatom-Cosmic");
    if (!cosmic?.exists) return;

    const oldMaxhp = source.maxhp;
    const oldHp = source.hp;
    const changed = source.formeChange(cosmic, this.effect, true) || source.formeChange("Terapagosatom-Cosmic", this.effect, true) || source.formeChange("terapagosatomcosmic", this.effect, true);
    if (!changed) return;

    source.addVolatile("universeexpansiontransformed");
    source.setSpecies(cosmic);

    if (source.maxhp && oldMaxhp && source.maxhp !== oldMaxhp) {
      source.hp = source.maxhp - (oldMaxhp - oldHp);
      if (source.hp > source.maxhp) source.hp = source.maxhp;
      if (source.hp < 1) source.hp = 1;
    }

    this.add("-formechange", source, "Terapagosatom-Cosmic", "[from] move: Universe Expansion");
  },

  condition: {},
  secondary: null,
  target: "normal",
  type: "Normal",
  contestType: "Beautiful"
}
