// automatically generated by TableCodeGenerator, do not modify
package com.riiablo.table.table;

import javax.annotation.Generated;

import com.badlogic.gdx.utils.IntMap;

import com.riiablo.logger.LogManager;
import com.riiablo.logger.Logger;
import com.riiablo.table.Manifest;
import com.riiablo.table.Parser;
import com.riiablo.table.ParserInput;
import com.riiablo.table.Serializer;
import com.riiablo.table.Table;
import com.riiablo.table.parser.RunesParser;
import com.riiablo.table.schema.Runes;
import com.riiablo.table.serializer.RunesSerializer;

@Generated(
    value = "com.riiablo.table.annotation.TableCodeGenerator",
    date = "2020-12-20T01:19:44-08:00",
    comments = "com.riiablo.table.schema.Runes"
)
public final class RunesTable extends Table<Runes> {
  private static final Logger log = LogManager.getLogger(RunesTable.class);

  public RunesTable(Manifest manifest) {
    super(manifest, Runes.class, 53, 0.8f);
  }

  @Override
  protected Runes newRecord() {
    return new Runes();
  }

  @Override
  protected Parser<Runes> newParser(ParserInput arg0) {
    return new RunesParser(arg0);
  }

  @Override
  protected Serializer<Runes> newSerializer() {
    return new RunesSerializer();
  }

  @Override
  protected int offset() {
    return 26;
  }

  @Override
  protected boolean indexed() {
    return false;
  }

  @Override
  protected boolean preload() {
    return true;
  }

  @Override
  protected String primaryKey() {
    return "Name";
  }

  private int map(Runes record) {
    final int oldId = Integer.parseInt(record.Name.substring(8)); // "Runeword"
    switch (oldId) {
      case 1: return 27; // Ancient's Pledge
      case 4: return 30; // Beast (The Beast)
      case 6: return 32; // Black
      case 8: return 34; // Bone
      case 9: return 35; // Bramble
      case 10: return 36; // Brand
      case 11: return 37; // Breath of the Dying
      case 13: return 39; // Call to Arms
      case 14: return 40; // Chains of Honor (Bound by Duty)
      case 16: return 42; // Chaos
      case 17: return 43; // Crescent Moon
      case 20: return 46; // Death
      case 22: return 2718; // Delirium
      case 25: return 51; // Destruction
      case 26: return 52; // Doom (Doomsayer)
      case 27: return 53; // Dragon
      case 29: return 55; // Dream
      case 30: return 56; // Duress
      case 31: return 57; // Edge
      case 33: return 59; // Enigma
      case 34: return 60; // Enlightenment
      case 36: return 62; // Eternity
      case 37: return 63; // Exile (Exile's Path)
      case 38: return 64; // Faith
      case 39: return 65; // Famine
      case 41: return 67; // Fortitude
      case 44: return 70; // Fury
      case 45: return 71; // Gloom
      case 47: return 73; // Widowmaker
      case 48: return 74; // Hand of Justice
      case 49: return 75; // Harmony
      case 51: return 77; // Heart of the Oak
      case 54: return 80; // Holy Thunder
      case 55: return 81; // Honor
      case 59: return 85; // Ice
      case 60: return 86; // Infinity
      case 62: return 88; // Insight
      case 65: return 91; // King's Grace
      case 66: return 92; // Kingslayer
      case 69: return 95; // Last Wish
      case 71: return 97; // Lawbringer
      case 72: return 98; // Leaf
      case 74: return 100; // Lionheart
      case 75: return 101; // Lore
      case 81: return 106; // Malice
      case 82: return 107; // Melody
      case 83: return 108; // Memory
      case 87: return 112; // Myth
      case 88: return 113; // Nadir
      case 91: return 116; // Oath
      case 92: return 117; // Obedience
      case 95:
        if (record.Rune_Name.equalsIgnoreCase("PASSION")) {
          return 120; // Passion
        } else {
          return -1; // Patience
        }
      case 98: return 123; // Peace
      case 99: return 124; // Winter
      case 103: return 128; // Phoenix
      case 109: return 134; // Pride
      case 110: return 135; // Principle
      case 112: return 137; // Prudence
      case 116: return 141; // Radiance
      case 117: return 142; // Rain
      case 120: return 145; // Rhyme
      case 121: return 146; // Rift
      case 122: return 147; // Sanctuary
      case 126: return 151; // Silence
      case 128: return 153; // Smoke
      case 130: return 155; // Spirit
      case 131: return 156; // Splendor
      case 133: return 158; // Stealth
      case 134: return 159; // Steel
      case 137: return 162; // Stone
      case 139: return 164; // Strength
      case 148: return 173; // Treachery
      case 154: return 179; // Venom
      case 160: return 185; // Wealth
      case 162: return 187; // White
      case 163: return 188; // Wind
      case 168: return 193; // Wrath
      case 170: return 195; // Zephyr
      default: return -1;
    }
  }

  @Override
  protected void initialize() {
    log.trace("initializing...");
    final int offset = offset();
    IntMap<Runes> remap = new IntMap<>();
    for (Runes record : records.values()) {
      final int newId = map(record);
      log.trace("{}: {} -> {}", record.Name, record.Rune_Name, newId);
      if (newId >= 0) remap.put(newId, record);
    }

    records = remap;
    log.debug("initialized {} records", records.size);
  }
}
