"""
Migration 35

- Remove builtin damage patterns and target profiles from the database
"""

import sqlalchemy


dmgPatterns = (
    'Uniform',
    '[Bombs]Concussion Bomb',
    '[Bombs]Electron Bomb',
    '[Bombs]Scorch Bomb',
    '[Bombs]Shrapnel Bomb',
    '[Exotic Plasma]Baryon',
    '[Exotic Plasma]Meson',
    '[Exotic Plasma]Tetryon',
    '[Exotic Plasma][T2] Mystic',
    '[Exotic Plasma][T2] Occult',
    '[Frequency Crystals]Gamma',
    '[Frequency Crystals]Infrared',
    '[Frequency Crystals]Microwave',
    '[Frequency Crystals]Multifrequency',
    '[Frequency Crystals]Radio',
    '[Frequency Crystals]Standard',
    '[Frequency Crystals]Ultraviolet',
    '[Frequency Crystals]Xray',
    '[Frequency Crystals][T2] Aurora',
    '[Frequency Crystals][T2] Conflagration',
    '[Frequency Crystals][T2] Gleam',
    '[Frequency Crystals][T2] Scorch',
    '[Generic]EM',
    '[Generic]Explosive',
    '[Generic]Kinetic',
    '[Generic]Thermal',
    '[Hybrid Charges]Antimatter',
    '[Hybrid Charges]Iridium',
    '[Hybrid Charges]Iron',
    '[Hybrid Charges]Lead',
    '[Hybrid Charges]Plutonium',
    '[Hybrid Charges]Thorium',
    '[Hybrid Charges]Tungsten',
    '[Hybrid Charges]Uranium',
    '[Hybrid Charges][T2] Javelin',
    '[Hybrid Charges][T2] Null',
    '[Hybrid Charges][T2] Spike',
    '[Hybrid Charges][T2] Void',
    '[Missiles]Inferno',
    '[Missiles]Mjolnir',
    '[Missiles]Nova',
    '[Missiles]Scourge',
    '[Missiles][Structure) Standup Missile',
    '[Missiles][Structure] Standup Missile',
    '[NPC][Asteroid] Angel Cartel',
    '[NPC][Asteroid] Blood Raiders',
    '[NPC][Asteroid] Guristas',
    '[NPC][Asteroid] Rogue Drone',
    '[NPC][Asteroid] Sanshas Nation',
    '[NPC][Asteroid] Serpentis',
    '[NPC][Burner] Ashimmu (Blood Raiders)',
    '[NPC][Burner] Cruor (Blood Raiders)',
    '[NPC][Burner] Daredevil (Serpentis)',
    '[NPC][Burner] Dramiel (Angel)',
    '[NPC][Burner] Enyo',
    '[NPC][Burner] Hawk',
    '[NPC][Burner] Jaguar',
    '[NPC][Burner] Sentinel',
    '[NPC][Burner] Succubus (Sanshas Nation)',
    '[NPC][Burner] Talos',
    '[NPC][Burner] Vengeance',
    '[NPC][Burner] Worm (Guristas)',
    '[NPC][Deadspace] Angel Cartel',
    '[NPC][Deadspace] Blood Raiders',
    '[NPC][Deadspace] Guristas',
    '[NPC][Deadspace] Rogue Drone',
    '[NPC][Deadspace] Sanshas Nation',
    '[NPC][Deadspace] Serpentis',
    '[NPC][Mission] Amarr Empire',
    '[NPC][Mission] CONCORD',
    '[NPC][Mission] Caldari State',
    '[NPC][Mission] Gallente Federation',
    '[NPC][Mission] Khanid',
    '[NPC][Mission] Minmatar Republic',
    '[NPC][Mission] Mordus Legion',
    '[NPC][Mission] Thukker',
    '[NPC][Other] Sansha Incursion',
    '[NPC][Other] Sleepers',
    '[Projectile Ammo]Carbonized Lead',
    '[Projectile Ammo]Depleted Uranium',
    '[Projectile Ammo]EMP',
    '[Projectile Ammo]Fusion',
    '[Projectile Ammo]Nuclear',
    '[Projectile Ammo]Phased Plasma',
    '[Projectile Ammo]Proton',
    '[Projectile Ammo]Titanium Sabot',
    '[Projectile Ammo][T2] Barrage',
    '[Projectile Ammo][T2] Hail',
    '[Projectile Ammo][T2] Quake',
    '[Projectile Ammo][T2] Tremor')

tgtProfiles = (
    'Uniform (25%)',
    'Uniform (50%)',
    'Uniform (75%)',
    'Uniform (90%)',
    '[NPC][Asteroid] Angel Cartel',
    '[NPC][Asteroid] Blood Raiders',
    '[NPC][Asteroid] Guristas',
    '[NPC][Asteroid] Rogue Drones',
    '[NPC][Asteroid] Sanshas Nation',
    '[NPC][Asteroid] Serpentis',
    '[NPC][Burner] Ashimmu (Blood Raiders)',
    '[NPC][Burner] Cruor (Blood Raiders)',
    '[NPC][Burner] Daredevil (Serpentis)',
    '[NPC][Burner] Dramiel (Angel)',
    '[NPC][Burner] Enyo',
    '[NPC][Burner] Hawk',
    '[NPC][Burner] Jaguar',
    '[NPC][Burner] Sentinel',
    '[NPC][Burner] Succubus (Sanshas Nation)',
    '[NPC][Burner] Talos',
    '[NPC][Burner] Vengeance',
    '[NPC][Burner] Worm (Guristas)',
    '[NPC][Deadspace] Angel Cartel',
    '[NPC][Deadspace] Blood Raiders',
    '[NPC][Deadspace] Guristas',
    '[NPC][Deadspace] Rogue Drones',
    '[NPC][Deadspace] Sanshas Nation',
    '[NPC][Deadspace] Serpentis',
    '[NPC][Mission] Amarr Empire',
    '[NPC][Mission] CONCORD',
    '[NPC][Mission] Caldari State',
    '[NPC][Mission] Gallente Federation',
    '[NPC][Mission] Khanid',
    '[NPC][Mission] Minmatar Republic',
    '[NPC][Mission] Mordus Legion',
    '[NPC][Other] Sansha Incursion',
    '[NPC][Other] Sleeper',
    '[T1 Resist]Armor',
    '[T1 Resist]Armor (+T2 DCU)',
    '[T1 Resist]Hull',
    '[T1 Resist]Hull (+T2 DCU)',
    '[T1 Resist]Shield',
    '[T1 Resist]Shield (+T2 DCU)',
    '[T2 Resist]Amarr (Armor)',
    '[T2 Resist]Amarr (Shield)',
    '[T2 Resist]Caldari (Armor)',
    '[T2 Resist]Caldari (Shield)',
    '[T2 Resist]Gallente (Armor)',
    '[T2 Resist]Gallente (Shield)',
    '[T2 Resist]Minmatar (Armor)',
    '[T2 Resist]Minmatar (Shield)')


def upgrade(saveddata_engine):
    saveddata_engine.execute('DELETE FROM damagePatterns WHERE name in ({});'.format(', '.join('\'{}\''.format(n) for n in dmgPatterns)))
    saveddata_engine.execute('DELETE FROM targetResists WHERE name in ({});'.format(', '.join('\'{}\''.format(n) for n in tgtProfiles)))
    try:
        saveddata_engine.execute("SELECT builtinDamagePatternID FROM fits LIMIT 1")
    except sqlalchemy.exc.DatabaseError:
        saveddata_engine.execute("ALTER TABLE fits ADD COLUMN builtinDamagePatternID INT;")
    try:
        saveddata_engine.execute("SELECT builtinTargetResistsID FROM fits LIMIT 1")
    except sqlalchemy.exc.DatabaseError:
        saveddata_engine.execute("ALTER TABLE fits ADD COLUMN builtinTargetResistsID INT;")
