import * as M from "./factorio-dump.models.ts";
import type { Group } from "./helpers/groups.helper.ts";
import type { Recipe } from "./helpers/recipes.helper.ts";

export interface ModList {
  mods: { name: string; enabled: boolean }[];
}

export type EffectType = "speed" | "productivity" | "consumption" | "pollution" | "quality";

export const allEffects: EffectType[] = ["consumption", "speed", "productivity", "pollution", "quality"];
type Entities<T = string> = Record<string, T>;
export interface DataRawDump {
  "agricultural-tower"?: Entities<M.AgriculturalTowerPrototype>;
  ammo: Entities<M.AmmoItemPrototype>;
  armor: Entities<M.ArmorPrototype>;
  "assembling-machine": Entities<M.AssemblingMachinePrototype>;
  asteroid?: Entities<M.AsteroidPrototype>;
  "asteroid-chunk": Entities<M.AsteroidChunkPrototype>;
  "asteroid-collector"?: Entities<M.AsteroidCollectorPrototype>;
  beacon: Entities<M.BeaconPrototype>;
  boiler: Entities<M.BoilerPrototype>;
  capsule: Entities<M.CapsulePrototype>;
  "cargo-wagon": Entities<M.CargoWagonPrototype>;
  fluid: Entities<M.FluidPrototype>;
  "fluid-wagon": Entities<M.FluidWagonPrototype>;
  furnace: Entities<M.FurnacePrototype>;
  gun: Entities<M.GunPrototype>;
  item: Entities<M.ItemPrototype>;
  "item-group": Entities<M.ItemGroup>;
  "item-subgroup": Entities<M.ItemSubGroup>;
  "item-with-entity-data": Entities<M.ItemWithEntityDataPrototype>;
  lab: Entities<M.LabPrototype>;
  "mining-drill": Entities<M.MiningDrillPrototype>;
  module: Entities<M.ModulePrototype>;
  "offshore-pump": Entities<M.OffshorePumpPrototype>;
  planet: Entities<M.PlanetPrototype>;
  plant: Entities<M.PlantPrototype>;
  pump: Entities<M.PumpPrototype>;
  quality: Entities<M.QualityPrototype>;
  "rail-planner": Entities<M.RailPlannerPrototype>;
  reactor: Entities<M.ReactorPrototype>;
  recipe: Entities<M.RecipePrototype>;
  "recipe-category": Entities<M.RecipeCategory>;
  "repair-tool": Entities<M.RepairToolPrototype>;
  resource: Entities<M.ResourceEntityPrototype>;
  "rocket-silo": Entities<M.RocketSiloPrototype>;
  "rocket-silo-rocket": Entities<M.RocketSiloRocketPrototype>;
  "selection-tool": Entities<M.SelectionToolPrototype>;
  "space-connection"?: Entities<M.SpaceConnectionPrototype>;
  "space-location": Entities<M.SpaceLocationPrototype>;
  "space-platform-starter-pack"?: Entities<M.SpacePlatformStarterPackPrototype>;
  "spidertron-remote": Entities<M.SpidertronRemotePrototype>;
  surface: Entities<M.SurfacePrototype>;
  "surface-property": Entities<M.SurfacePropertyPrototype>;
  technology: Entities<M.TechnologyPrototype>;
  tile: Entities<M.TilePrototype>;
  tool: Entities<M.ToolPrototype>;
  "transport-belt": Entities<M.TransportBeltPrototype>;
  "utility-constants": { default: M.UtilityConstants };
  "virtual-signal": Entities<M.VirtualSignalPrototype>;
}

export interface Locale {
  names: Entities;
}
export type Item = {
  name: string;
  icon?: string;
  subgroup: string;
  order?: string;
};
export type Machine = {
  name: string;
  icon?: string;
  allowed_effects?: string | Array<string>;
  crafting_categories: string[];
  crafting_speed: number;
  selection_box?: M.BoundingBox;
  module_slots?: number;
  effect_receiver?: M.EffectReceiver;
};
export type Module = {
  name: string;
  icon?: string;
  subgroup?: string;
  category: string;
  tier: number;
  order?: string;
  effect?: M.Effect;
};

export type RecipeCategory = {
  name: string;
  subgroup?: string;
  order?: string;
};
export type Quality = M.QualityPrototype & {
  icon: string;
};
export type Signal = {
  name: string;
  icon?: string;
  subgroup: string;
  order?: string;
};
export type ProcessedData = {
  machines: Machine[];
  qualityLevels: Quality[];
  modules: Module[];
  recipeCategories: RecipeCategory[];
  recipeGroup: Group<Recipe>[];
  signalGroup: Group<Signal>[];
};
