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-13")]
    class dvb_iso_8859_13 : SkyscraperBaseEncoding8
    {
        protected override char[] Decrypt(byte[] preprocessed)
        {
            StringBuilder resultBuilder = new StringBuilder();
            for (int i = 0; i < preprocessed.Length; i++)
            {
                if (preprocessed[i] <= 0x7f)
                {
                    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 0xa5: resultBuilder.Append('„'); break;
                    case 0xa7: resultBuilder.Append('§'); break;
                    case 0xa8: resultBuilder.Append('Ø'); break;
                    case 0xa9: resultBuilder.Append('©'); break;
                    case 0xaa: 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 0xaf: resultBuilder.Append('Æ'); break;
                    case 0xb0: resultBuilder.Append('°'); break;
                    case 0xb4: resultBuilder.Append('“'); break;
                    case 0xb8: resultBuilder.Append('ø'); break;
                    case 0xb9: resultBuilder.Append('¹'); break;
                    case 0xbb: resultBuilder.Append('»'); break;
                    case 0xbf: 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 0xcc: resultBuilder.Append('Ģ'); break;
                    case 0xce: resultBuilder.Append('Ī'); break;
                    case 0xcf: resultBuilder.Append('Ļ'); break;
                    case 0xd0: resultBuilder.Append('Š'); break;
                    case 0xd1: resultBuilder.Append('Ń'); break;
                    case 0xd3: resultBuilder.Append('Ó'); break;
                    case 0xd4: resultBuilder.Append('Ō'); break;
                    case 0xd6: resultBuilder.Append('Ö'); break;
                    case 0xd9: resultBuilder.Append('Ł'); break;
                    case 0xda: resultBuilder.Append('Ś'); break;
                    case 0xdc: resultBuilder.Append('Ü'); break;
                    case 0xdd: resultBuilder.Append('Ż'); break;
                    case 0xde: resultBuilder.Append('Ž'); break;
                    case 0xdf: resultBuilder.Append('ß'); break;
                    case 0xe0: 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 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 0xf0: resultBuilder.Append('š'); break;
                    case 0xf1: resultBuilder.Append('ń'); break;
                    case 0xf2: resultBuilder.Append('ņ'); break;
                    case 0xf3: resultBuilder.Append('ó'); break;
                    case 0xf5: resultBuilder.Append('õ'); break;
                    case 0xf6: 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 0xfe: resultBuilder.Append('ž'); break;
                        case 0xff: resultBuilder.Append('’'); break;
                        default:
                            throw new NotImplementedException(String.Format("0x{0:X2}", preprocessed[i]));
                        }
            }

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