﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace KrassequenzerTester
{
	class ParseTheShit
	{
		/// <summary>
		/// Parses the shit and writes C# code for an enum.
		/// </summary>
		public static void Run()
		{
			var theShit = @"1.	Acoustic Grand Piano	65.	Soprano Sax
2.	Bright Acoustic Piano	66.	Alto Sax
3.	Electric Grand Piano	67.	Tenor Sax
4.	Honky-tonk Piano	68.	Baritone Sax
5.	Electric Piano 1	69.	Oboe
6.	Electric Piano 2	70.	English Horn
7.	Harpsichord	71.	Bassoon
8.	Clavi	72.	Clarinet
9.	Celesta	73.	Piccolo
10.	Glockenspiel	74.	Flute
11.	Music Box	75.	Recorder
12.	Vibraphone	76.	Pan Flute
13.	Marimba	77.	Blown Bottle
14.	Xylophone	78.	Shakuhachi
15.	Tubular Bells	79.	Whistle
16.	Dulcimer	80.	Ocarina
17.	Drawbar Organ	81.	Lead 1 (square)
18.	Percussive Organ	82.	Lead 2 (sawtooth)
19.	Rock Organ	83.	Lead 3 (calliope)
20.	Church Organ	84.	Lead 4 (chiff)
21.	Reed Organ	85.	Lead 5 (charang)
22.	Accordion	86.	Lead 6 (voice)
23.	Harmonica	87.	Lead 7 (fifths)
24.	Tango Accordion	88.	Lead 8 (bass + lead)
25.	Acoustic Guitar (nylon)	89.	Pad 1 (new age)
26.	Acoustic Guitar (steel)	90.	Pad 2 (warm)
27.	Electric Guitar (jazz)	91.	Pad 3 (polysynth)
28.	Electric Guitar (clean)	92.	Pad 4 (choir)
29.	Electric Guitar (muted)	93.	Pad 5 (bowed)
30.	Overdriven Guitar	94.	Pad 6 (metallic)
31.	Distortion Guitar	95.	Pad 7 (halo)
32.	Guitar harmonics	96.	Pad 8 (sweep)
33.	Acoustic Bass	97.	FX 1 (rain)
34.	Electric Bass (finger)	98.	FX 2 (soundtrack)
35.	Electric Bass (pick)	99.	FX 3 (crystal)
36.	Fretless Bass	100.	FX 4 (atmosphere)
37.	Slap Bass 1	101.	FX 5 (brightness)
38.	Slap Bass 2	102.	FX 6 (goblins)
39.	Synth Bass 1	103.	FX 7 (echoes)
40.	Synth Bass 2	104.	FX 8 (sci-fi)
41.	Violin	105.	Sitar
42.	Viola	106.	Banjo
43.	Cello	107.	Shamisen
44.	Contrabass	108.	Koto
45.	Tremolo Strings	109.	Kalimba
46.	Pizzicato Strings	110.	Bag pipe
47.	Orchestral Harp	111.	Fiddle
48.	Timpani	112.	Shanai
49.	String Ensemble 1	113.	Tinkle Bell
50.	String Ensemble 2	114.	Agogo
51.	SynthStrings 1	115.	Steel Drums
52.	SynthStrings 2	116.	Woodblock
53.	Choir Aahs	117.	Taiko Drum
54.	Voice Oohs	118.	Melodic Tom
55.	Synth Voice	119.	Synth Drum
56.	Orchestra Hit	120.	Reverse Cymbal
57.	Trumpet	121.	Guitar Fret Noise
58.	Trombone	122.	Breath Noise
59.	Tuba	123.	Seashore
60.	Muted Trumpet	124.	Bird Tweet
61.	French Horn	125.	Telephone Ring
62.	Brass Section	126.	Helicopter
63.	SynthBrass 1	127.	Applause
64.	SynthBrass 2	128.	Gunshot";

			var listOfTheShit = new List<Tuple<int, string>>();
			var match = Regex.Match(theShit, @"^(?<LeNo>[0-9]+)\.\t(?<LeNa>.+?)\t(?<RiNo>[0-9]+)\.\t(?<RiNa>.+?)\s*$", RegexOptions.Multiline);
			while (match.Success)
			{
				var leNo = Int32.Parse(match.Groups["LeNo"].Value);
				var leNa = match.Groups["LeNa"].Value;
				var riNo = Int32.Parse(match.Groups["RiNo"].Value);
				var riNa = match.Groups["RiNa"].Value;
				var le = new Tuple<int, string>(leNo, leNa);
				var ri = new Tuple<int, string>(riNo, riNa);
				listOfTheShit.Add(le);
				listOfTheShit.Add(ri);
				match = match.NextMatch();
			}

			foreach (var shit in listOfTheShit.OrderBy(x => x.Item1))
			{
				Debug.WriteLine("/// <summary>");
				Debug.WriteLine("/// " + shit.Item2);
				Debug.WriteLine("/// </summary>");
				
				var compileSafeName = Regex.Replace(shit.Item2.Replace(' ', '_'), @"[^a-zA-Z0-9_]", "");
				var enumValue = shit.Item1 - 1;
				Debug.WriteLine(compileSafeName + " = " + enumValue.ToString() + ", ");
			}
		}
	}
}
