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-14")]
    class dvb_iso_8859_14 : 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 0xaf: resultBuilder.Append('Ÿ'); break;
                    case 0xa3: resultBuilder.Append('£'); break;
                    case 0xb4: resultBuilder.Append('Ṁ'); break;
                    case 0xb5: resultBuilder.Append('ṁ'); break;
                    case 0xb7: resultBuilder.Append('Ṗ'); break;
                    case 0xb8: resultBuilder.Append('ẁ'); break;
                    case 0xba: resultBuilder.Append('ẃ'); break;
                    case 0xbd: resultBuilder.Append('Ẅ'); break;
                    case 0xc1: resultBuilder.Append('Á'); break;
                    case 0xc2: resultBuilder.Append('Â'); break;
                    case 0xc3: resultBuilder.Append('Ã'); break;
                    case 0xc7: resultBuilder.Append('Ç'); break;
                    case 0xc8: resultBuilder.Append('È'); break;
                    case 0xcb: resultBuilder.Append('Ë'); break;
                    case 0xcf: resultBuilder.Append('Ï'); break;
                    case 0xd2: resultBuilder.Append('Ò'); break;
                    case 0xd6: resultBuilder.Append('Ö'); break;
                    case 0xd8: resultBuilder.Append('Ø'); break;
                    case 0xd9: resultBuilder.Append('Ù'); break;
                    case 0xda: resultBuilder.Append('Ú'); break;
                    case 0xe0: resultBuilder.Append('à'); break;
                    case 0xe1: resultBuilder.Append('á'); break;
                    case 0xe3: resultBuilder.Append('ã'); break;
                    case 0xe4: resultBuilder.Append('ä'); break;
                    case 0xe7: resultBuilder.Append('ç'); break;
                    case 0xe8: resultBuilder.Append('è'); break;
                    case 0xe9: resultBuilder.Append('é'); break;
                    case 0xea: resultBuilder.Append('ê'); break;
                    case 0xed: resultBuilder.Append('í'); break;
                    case 0xf0: resultBuilder.Append('ŵ'); break;
                    case 0xf2: resultBuilder.Append('ò'); break;
                    case 0xf3: resultBuilder.Append('ó'); break;
                    case 0xfa: resultBuilder.Append('ú'); break;
                    case 0xfc: resultBuilder.Append('ü'); break;
                    case 0xfd: resultBuilder.Append('ý'); break;
                    case 0xfe: resultBuilder.Append('ŷ'); break;
                    default:
                        throw new NotImplementedException(String.Format("0x{0:X2}", preprocessed[i]));
                }
            }

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