///|
pub struct RuntimePreset {
  name : String
  target : RuntimeTarget
  extension : String
  indent : Int
  include_diagnostics : Bool
  include_slices : Bool
} derive(Debug, Eq, ToJson, FromJson)

///|
pub fn RuntimePreset::options(self : RuntimePreset) -> RuntimeOptions {
  {
    target: self.target,
    indent: self.indent,
    include_diagnostics: self.include_diagnostics,
    include_slices: self.include_slices,
  }
}

///|
pub fn RuntimePreset::adapter(self : RuntimePreset) -> RuntimeAdapter {
  RuntimeAdapter::for_target(self.target)
}

///|
pub fn RuntimePreset::to_json_string(
  self : RuntimePreset,
  indent? : Int = 2,
) -> String {
  self.to_json().stringify(indent~)
}

///|
pub fn runtime_presets() -> Array[RuntimePreset] {
  [
    {
      name: "runtime_1",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_2",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_3",
      target: MoonBit,
      extension: "mbt.json",
      indent: 0,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_4",
      target: Generic,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_5",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: false,
    },
    {
      name: "runtime_6",
      target: Phaser,
      extension: "json",
      indent: 0,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_7",
      target: MoonBit,
      extension: "mbt.json",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_8",
      target: Generic,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_9",
      target: Godot,
      extension: "tres",
      indent: 0,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_10",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: false,
    },
    {
      name: "runtime_11",
      target: MoonBit,
      extension: "mbt.json",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_12",
      target: Generic,
      extension: "json",
      indent: 0,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_13",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_14",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_15",
      target: MoonBit,
      extension: "mbt.json",
      indent: 0,
      include_diagnostics: false,
      include_slices: false,
    },
    {
      name: "runtime_16",
      target: Generic,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_17",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_18",
      target: Phaser,
      extension: "json",
      indent: 0,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_19",
      target: MoonBit,
      extension: "mbt.json",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_20",
      target: Generic,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: false,
    },
    {
      name: "runtime_21",
      target: Godot,
      extension: "tres",
      indent: 0,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_22",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_23",
      target: MoonBit,
      extension: "mbt.json",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_24",
      target: Generic,
      extension: "json",
      indent: 0,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_25",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: false,
    },
    {
      name: "runtime_26",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_27",
      target: MoonBit,
      extension: "mbt.json",
      indent: 0,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_28",
      target: Generic,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_29",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_30",
      target: Phaser,
      extension: "json",
      indent: 0,
      include_diagnostics: true,
      include_slices: false,
    },
    {
      name: "runtime_31",
      target: MoonBit,
      extension: "mbt.json",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_32",
      target: Generic,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_33",
      target: Godot,
      extension: "tres",
      indent: 0,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_34",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_35",
      target: MoonBit,
      extension: "mbt.json",
      indent: 2,
      include_diagnostics: false,
      include_slices: false,
    },
    {
      name: "runtime_36",
      target: Generic,
      extension: "json",
      indent: 0,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_37",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_38",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_39",
      target: MoonBit,
      extension: "mbt.json",
      indent: 0,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_40",
      target: Generic,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: false,
    },
    {
      name: "runtime_41",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_42",
      target: Phaser,
      extension: "json",
      indent: 0,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_43",
      target: MoonBit,
      extension: "mbt.json",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_44",
      target: Generic,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_45",
      target: Godot,
      extension: "tres",
      indent: 0,
      include_diagnostics: false,
      include_slices: false,
    },
    {
      name: "runtime_46",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_47",
      target: MoonBit,
      extension: "mbt.json",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_48",
      target: Generic,
      extension: "json",
      indent: 0,
      include_diagnostics: true,
      include_slices: true,
    },
    {
      name: "runtime_49",
      target: Godot,
      extension: "tres",
      indent: 2,
      include_diagnostics: false,
      include_slices: true,
    },
    {
      name: "runtime_50",
      target: Phaser,
      extension: "json",
      indent: 2,
      include_diagnostics: true,
      include_slices: false,
    },
  ]
}

///|
pub fn runtime_preset_named(name : String) -> RuntimePreset? {
  match runtime_presets().search_by(fn(preset) { preset.name == name }) {
    Some(index) => Some(runtime_presets()[index])
    None => None
  }
}

///|
pub fn runtime_preset_count() -> Int {
  runtime_presets().length()
}

///|
pub fn runtime_presets_for(target : RuntimeTarget) -> Array[RuntimePreset] {
  runtime_presets().filter(fn(preset) { preset.target == target })
}