using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper5.Skyscraper.Text.Encodings
{
    [SkyscraperEncoding("dvb-iso-8859-15")]
    class dvb_iso_8859_15 : SkyscraperBaseEncoding8
    {
        protected override char[] Decrypt(byte[] preprocessed)
        {
            StringBuilder resultBuilder = new StringBuilder();
            for (int i = 0; i < preprocessed.Length; i++)
            {
                if (preprocessed[i] <= 0x7e)
                {
                    AsciiTable.GetAsciiChar(preprocessed[i], resultBuilder);
                    continue;
                }
                switch (preprocessed[i])
                {
                    case 0xa0: resultBuilder.Append('\u00a0'); break;
                    case 0xa1: resultBuilder.Append('¡'); break;
                    case 0xa2: resultBuilder.Append('¢'); break;
                    case 0xa3: resultBuilder.Append('£'); break;
                    case 0xa4: resultBuilder.Append('€'); break;
                    case 0xa6: resultBuilder.Append('Š'); break;
                    case 0xa7: resultBuilder.Append('§'); break;
                    case 0xa8: resultBuilder.Append('š'); break;
                    case 0xa9: resultBuilder.Append('©'); break;
                    case 0xab: resultBuilder.Append('«'); break;
                    case 0xac: resultBuilder.Append('¬'); break;
                    case 0xad: resultBuilder.Append('\u00ad'); break;
                    case 0xae: resultBuilder.Append('®'); break;
                    case 0xb0: resultBuilder.Append('°'); break;
                    case 0xb1: resultBuilder.Append('±'); break;
                    case 0xb2: resultBuilder.Append('²'); break;
                    case 0xb3: resultBuilder.Append('³'); break;
                    case 0xb4: resultBuilder.Append('Ž'); break;
                    case 0xb6: resultBuilder.Append('¶'); break;
                    case 0xb7: resultBuilder.Append('·'); break;
                    case 0xb8: resultBuilder.Append('ž'); break;
                    case 0xba: resultBuilder.Append('º'); break;
                    case 0xbb: resultBuilder.Append('»'); break;
                    case 0xbc: resultBuilder.Append('Œ'); break;
                    case 0xbd: resultBuilder.Append('œ'); break;
                    case 0xbe: resultBuilder.Append('Ÿ'); break;
                    case 0xbf: resultBuilder.Append('¿'); break;
                    case 0xc0: resultBuilder.Append('À'); break;
                    case 0xc1: resultBuilder.Append('Α'); break;
                    case 0xc2: resultBuilder.Append('Â'); break;
                    case 0xc3: resultBuilder.Append('Ã'); break;
                    case 0xc4: resultBuilder.Append('Ä'); break;
                    case 0xc5: resultBuilder.Append('Å'); break;
                    case 0xc7: resultBuilder.Append('Ç'); break;
                    case 0xc8: resultBuilder.Append('È'); break;
                    case 0xc9: resultBuilder.Append('É'); break;
                    case 0xca: resultBuilder.Append('Ê'); break;
                    case 0xcd: resultBuilder.Append('Í'); break;
                    case 0xce: resultBuilder.Append('Î'); break;
                    case 0xd2: resultBuilder.Append('Ò'); break;
                    case 0xd3: resultBuilder.Append('Ó'); break;
                    case 0xd4: resultBuilder.Append('Ô'); break;
                    case 0xd6: resultBuilder.Append('Ö'); break;
                    case 0xd7: resultBuilder.Append('×'); break;
                    case 0xd8: resultBuilder.Append('Ø'); break;
                    case 0xda: resultBuilder.Append('Ú'); break;
                    case 0xdc: resultBuilder.Append('Ü'); break;
                    case 0xdf: resultBuilder.Append('ß'); break;
                    case 0xe0: resultBuilder.Append('à'); break;
                    case 0xe1: resultBuilder.Append('á'); break;
                    case 0xe2: resultBuilder.Append('â'); break;
                    case 0xe3: resultBuilder.Append('ã'); break;
                    case 0xe4: resultBuilder.Append('ä'); break;
                    case 0xe5: resultBuilder.Append('å'); break;
                    case 0xe6: resultBuilder.Append('æ'); break;
                    case 0xe7: resultBuilder.Append('ç'); break;
                    case 0xe8: resultBuilder.Append('è'); break;
                    case 0xe9: resultBuilder.Append('é'); break;
                    case 0xea: resultBuilder.Append('ê'); break;
                    case 0xeb: resultBuilder.Append('ë'); break;
                    case 0xec: resultBuilder.Append('ì'); break;
                    case 0xed: resultBuilder.Append('í'); break;
                    case 0xee: resultBuilder.Append('î'); break;
                    case 0xef: resultBuilder.Append('ï'); break;
                    case 0xf0: resultBuilder.Append('ð'); break;
                    case 0xf1: resultBuilder.Append('ñ'); break;
                    case 0xf2: resultBuilder.Append('ò'); break;
                    case 0xf3: resultBuilder.Append('ó'); break;
                    case 0xf4: resultBuilder.Append('ô'); break;
                    case 0xf5: resultBuilder.Append('õ'); break;
                    case 0xf6: resultBuilder.Append('ö'); break;
                    case 0xf7: resultBuilder.Append('÷'); break;
                    case 0xf8: resultBuilder.Append('ø'); break;
                    case 0xf9: resultBuilder.Append('ù'); break;
                    case 0xfa: resultBuilder.Append('ú'); break;
                    case 0xfb: resultBuilder.Append('û'); break;
                    case 0xfc: resultBuilder.Append('ü'); break;
                    case 0xfd: resultBuilder.Append('ý'); break;
                    case 0xff: resultBuilder.Append('ÿ'); break;
                    default: 
                        throw new NotImplementedException(String.Format("0x{0:X2}", preprocessed[i]));
                }
            }

            return resultBuilder.ToString().ToCharArray();
        }
    }
}
