// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using bahnplan.web.JSON;
//
//    var ticketResponse = TicketResponse.FromJson(jsonString);

using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

namespace bahnplan.web.JSON {
	using J = JsonPropertyAttribute;
	using R = Required;
	using NV = NullValueHandling;

	public partial class TicketResponse {
		[J("?xml", NullValueHandling = NV.Ignore)]
		public Xml Xml { get; set; }

		[J("rporderdetails", NullValueHandling = NV.Ignore)]
		public Rporderdetails Rporderdetails { get; set; }
	}

	public class Rporderdetails {
		[J("rpheader", NullValueHandling = NV.Ignore)]
		public Rpheader Rpheader { get; set; }

		[J("@version", NullValueHandling = NV.Ignore)]
		public string Version { get; set; }

		[J("order", NullValueHandling = NV.Ignore)]
		public Order Order { get; set; }
	}

	public class Order {
		[J("@cid", NullValueHandling = NV.Ignore)]
		public string Cid { get; set; }

		[J("@cdt", NullValueHandling = NV.Ignore)]
		public string Cdt { get; set; }

		[J("schedulelist", NullValueHandling = NV.Ignore)]
		public Schedulelist Schedulelist { get; set; }

		[J("tcklist", NullValueHandling = NV.Ignore)]
		public Tcklist Tcklist { get; set; }

		[J("@sdt", NullValueHandling = NV.Ignore)]
		public string Sdt { get; set; }

		[J("@zweg", NullValueHandling = NV.Ignore)]
		public string Zweg { get; set; }

		[J("@vto", NullValueHandling = NV.Ignore)]
		public string Vto { get; set; }

		[J("@vfrom", NullValueHandling = NV.Ignore)]
		public string Vfrom { get; set; }

		[J("@ldt", NullValueHandling = NV.Ignore)]
		public string Ldt { get; set; }

		[J("@pg", NullValueHandling = NV.Ignore)]
		public string Pg { get; set; }

		[J("posinfolist", NullValueHandling = NV.Ignore)]
		public Posinfolist Posinfolist { get; set; }

		[J("@on", NullValueHandling = NV.Ignore)]
		public string On { get; set; }

		[J("txt", NullValueHandling = NV.Ignore)]
		public string Txt { get; set; }

		[J("@hkey", NullValueHandling = NV.Ignore)]
		public string Hkey { get; set; }

		[J("reslist", NullValueHandling = NV.Ignore)]
		public Reslist Reslist { get; set; }

		[J("@ddt", NullValueHandling = NV.Ignore)]
		public string Ddt { get; set; }

		[J("@version", NullValueHandling = NV.Ignore)]
		public string Version { get; set; }

		[J("@fkat", NullValueHandling = NV.Ignore)]
		public string Fkat { get; set; }
	}

	public class Posinfolist {
		[J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter<PosinfoElement>))]
		public List<PosinfoElement> Posinfo { get; set; }
	}

	public class FluffyChildlist {
		[J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter<PosinfoElement>))]
		public List<PosinfoElement> Posinfo { get; set; }
	}

	public class PurplePosinfo {
		[J("@state", NullValueHandling = NV.Ignore)]
		public string State { get; set; }

		[J("@dir", NullValueHandling = NV.Ignore)]
		public string Dir { get; set; }

		[J("@posnr", NullValueHandling = NV.Ignore)]
		public string Posnr { get; set; }

		[J("@type", NullValueHandling = NV.Ignore)]
		public string Type { get; set; }

		[J("@shownr", NullValueHandling = NV.Ignore)]
		public string Shownr { get; set; }

		[J("@dirlabel", NullValueHandling = NV.Ignore)]
		public string Dirlabel { get; set; }

		[J("@vfo", NullValueHandling = NV.Ignore)]
		public string Vfo { get; set; }

		[J("@typeinfo", NullValueHandling = NV.Ignore)]
		public string Typeinfo { get; set; }

		[J("@vto", NullValueHandling = NV.Ignore)]
		public string Vto { get; set; }

		[J("childlist", NullValueHandling = NV.Ignore)]
		public FluffyChildlist Childlist { get; set; }
	}

	public class PurpleChildlist {
		[J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter<PurplePosinfo>))]
		public List<PurplePosinfo> Posinfo { get; set; }
	}

	public class PosinfoElement {
		[J("@state", NullValueHandling = NV.Ignore)]
		public string State { get; set; }

		[J("@dir", NullValueHandling = NV.Ignore)]
		public string Dir { get; set; }

		[J("@posnr", NullValueHandling = NV.Ignore)]
		public string Posnr { get; set; }

		[J("@type", NullValueHandling = NV.Ignore)]
		public string Type { get; set; }

		[J("@shownr", NullValueHandling = NV.Ignore)]
		public string Shownr { get; set; }

		[J("@dirlabel", NullValueHandling = NV.Ignore)]
		public string Dirlabel { get; set; }

		[J("@vfo", NullValueHandling = NV.Ignore)]
		public string Vfo { get; set; }

		[J("@typeinfo", NullValueHandling = NV.Ignore)]
		public string Typeinfo { get; set; }

		[J("@vto", NullValueHandling = NV.Ignore)]
		public string Vto { get; set; }

		[J("childlist", NullValueHandling = NV.Ignore)]
		public PurpleChildlist Childlist { get; set; }
	}

	public class Reslist {
		[J("res", NullValueHandling = NV.Ignore)]
		public List<Re> Res { get; set; }
	}

	public class Re {
		[J("@tid", NullValueHandling = NV.Ignore)]
		public string Tid { get; set; }

		[J("@posnr", NullValueHandling = NV.Ignore)]
		public string Posnr { get; set; }

		[J("@dt", NullValueHandling = NV.Ignore)]
		public string Dt { get; set; }

		[J("nvplist", NullValueHandling = NV.Ignore)]
		public Nvplist Nvplist { get; set; }

		[J("@cdt", NullValueHandling = NV.Ignore)]
		public string Cdt { get; set; }

		[J("plaetze", NullValueHandling = NV.Ignore)]
		public Plaetze Plaetze { get; set; }

		[J("txt", NullValueHandling = NV.Ignore)]
		public string Txt { get; set; }

		[J("@tn", NullValueHandling = NV.Ignore)]
		public string Tn { get; set; }
	}

	public class Nvplist {
		[J("nvp", NullValueHandling = NV.Ignore)]
		public List<Nvp> Nvp { get; set; }
	}

	public class Nvp {
		[J("@name", NullValueHandling = NV.Ignore)]
		public string Name { get; set; }

		[J("#text", NullValueHandling = NV.Ignore)]
		public string Text { get; set; }
	}

	public class Plaetze {
		[J("platz", NullValueHandling = NV.Ignore)]
		public Platz Platz { get; set; }
	}

	public class Platz {
		[J("platznr", NullValueHandling = NV.Ignore)]
		public string Platznr { get; set; }

		[J("wagennr", NullValueHandling = NV.Ignore)]
		public string Wagennr { get; set; }
	}

	public class Schedulelist {
		[J("out", NullValueHandling = NV.Ignore)]
		public Journey Out { get; set; }

		[J("ret", NullValueHandling = NV.Ignore)]
		public Journey Ret { get; set; }
	}

	public class Journey {
		[J("txt", NullValueHandling = NV.Ignore)]
		public string Txt { get; set; }

		[J("@posnr", NullValueHandling = NV.Ignore)]
		public string Posnr { get; set; }

		[J("trainlist", NullValueHandling = NV.Ignore)]
		public Trainlist Trainlist { get; set; }
	}

	public class Trainlist {
		[J("train", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter<Train>))]
		public List<Train> Train { get; set; }
	}

	public class Train {
		[J("@tid", NullValueHandling = NV.Ignore)]
		public string Tid { get; set; }

		[J("@type", NullValueHandling = NV.Ignore)]
		public string Type { get; set; }

		[J("zugnr", NullValueHandling = NV.Ignore)]
		public string Zugnummer { get; set; }

		[J("arr", NullValueHandling = NV.Ignore)]
		public Station Arr { get; set; }

		[J("gat", NullValueHandling = NV.Ignore)]
		public string Gattung { get; set; }

		[J("sci", NullValueHandling = NV.Ignore)]
		public string Zugklasse { get; set; }

		[J("dep", NullValueHandling = NV.Ignore)]
		public Station Dep { get; set; }

		[J("@tn", NullValueHandling = NV.Ignore)]
		public string Line { get; set; }
	}

	public class Station {
		[J("x", NullValueHandling = NV.Ignore)]
		public string X { get; set; }

		[J("y", NullValueHandling = NV.Ignore)]
		public string Y { get; set; }

		[J("@dt", NullValueHandling = NV.Ignore)]
		public string Date { get; set; }

		[J("ebhf_name", NullValueHandling = NV.Ignore)]
		public string EbhfName { get; set; }

		[J("ebhf_nr", NullValueHandling = NV.Ignore)]
		public string EbhfNr { get; set; }

		[J("@t", NullValueHandling = NV.Ignore)]
		public string Time { get; set; }

		[J("n", NullValueHandling = NV.Ignore)]
		public string Name { get; set; }

		[J("nr", NullValueHandling = NV.Ignore)]
		public string BhfNr { get; set; }

		[J("plz", NullValueHandling = NV.Ignore)]
		public string Plz { get; set; }

		[J("ptf", NullValueHandling = NV.Ignore)]
		public string Ptf { get; set; }
	}

	public class Tcklist {
		[J("tck", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter<Tck>))]
		public List<Tck> Tck { get; set; }
	}

	public class Tck {
		[J("mtk", NullValueHandling = NV.Ignore)]
		public Mtk Mtk { get; set; }

		[J("@posnr", NullValueHandling = NV.Ignore)]
		public string Posnr { get; set; }

		[J("htdata", NullValueHandling = NV.Ignore)]
		public Htdata Htdata { get; set; }
	}

	public class Htdata {
		[J("ht", NullValueHandling = NV.Ignore)]
		public List<Ht> Ht { get; set; }
	}

	public class Ht {
		[J("@pos", NullValueHandling = NV.Ignore)]
		public string Pos { get; set; }

		[J("#text", NullValueHandling = NV.Ignore)]
		public string Text { get; set; }

		[J("@name", NullValueHandling = NV.Ignore)]
		public string Name { get; set; }

		[J("@type", NullValueHandling = NV.Ignore)]
		public string Type { get; set; }
	}

	public class Mtk {
		[J("@status", NullValueHandling = NV.Ignore)]
		public string Status { get; set; }

		[J("@dir", NullValueHandling = NV.Ignore)]
		public string Dir { get; set; }

		[J("iss", NullValueHandling = NV.Ignore)]
		public string Iss { get; set; }

		[J("tkey", NullValueHandling = NV.Ignore)]
		public string Tkey { get; set; }

		[J("bc", NullValueHandling = NV.Ignore)]
		public Bc Bc { get; set; }

		[J("nvplist", NullValueHandling = NV.Ignore)]
		public Nvplist Nvplist { get; set; }

		[J("reisender_vorname", NullValueHandling = NV.Ignore)]
		public string ReisenderVorname { get; set; }

		[J("reisender_nachname", NullValueHandling = NV.Ignore)]
		public string ReisenderNachname { get; set; }

		[J("txt", NullValueHandling = NV.Ignore)]
		public string Txt { get; set; }

		[J("zb", NullValueHandling = NV.Ignore)]
		public string Zb { get; set; }

		[J("ot_nr_hin", NullValueHandling = NV.Ignore)]
		public string OtNrHin { get; set; }
	}

	public class Bc {
		[J("rbs", NullValueHandling = NV.Ignore)]
		public string Rbs { get; set; }

		[J("anz", NullValueHandling = NV.Ignore)]
		public string Anz { get; set; }
	}

	public class Rpheader {
		[J("@ts", NullValueHandling = NV.Ignore)]
		public string Ts { get; set; }

		[J("@tnr", NullValueHandling = NV.Ignore)]
		public string Tnr { get; set; }
	}

	public class Xml {
		[J("@version", NullValueHandling = NV.Ignore)]
		public string Version { get; set; }

		[J("@encoding", NullValueHandling = NV.Ignore)]
		public string Encoding { get; set; }
	}

	public partial class TicketResponse {
		public static TicketResponse FromJson(string json) => JsonConvert.DeserializeObject<TicketResponse>(json, Converter.Settings);
	}

	internal static class Converter {
		public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings {
			MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
			DateParseHandling        = DateParseHandling.None,
			Converters               = {new IsoDateTimeConverter {DateTimeStyles = DateTimeStyles.AssumeUniversal}}
		};
	}

	internal class SingleOrArrayConverter<T> : JsonConverter {
		public override bool CanWrite => false;

		public override bool CanConvert(Type objectType) => objectType == typeof(List<T>);

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
			var token = JToken.Load(reader);
			return token.Type == JTokenType.Array ? token.ToObject<List<T>>() : new List<T> {token.ToObject<T>()};
		}

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
			throw new NotImplementedException();
		}
	}
}