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-3")]
    class dvb_iso_8859_3 : 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 0xb7: resultBuilder.Append('·'); break;
                    case 0xc0: resultBuilder.Append('À'); break;
                    case 0xc1: resultBuilder.Append('Á'); break;
                    case 0xc9: resultBuilder.Append('É'); break;
                    case 0xcd: resultBuilder.Append('Í'); break;
                    case 0xd1: resultBuilder.Append('Ñ'); break;
                    case 0xd2: resultBuilder.Append('Ò'); break;
                    case 0xd3: resultBuilder.Append('Ó'); break;
                    case 0xda: resultBuilder.Append('Ú'); break;
                    case 0xe0: resultBuilder.Append('à'); break;
                    case 0xe1: resultBuilder.Append('á'); break;
                    case 0xe7: resultBuilder.Append('ç'); break;
                    case 0xe8: resultBuilder.Append('è'); break;
                    case 0xe9: resultBuilder.Append('é'); break;
                    case 0xec: resultBuilder.Append('ì'); break;
                    case 0xed: resultBuilder.Append('í'); break;
                    case 0xef: resultBuilder.Append('ï'); break; 
                    case 0xf1: resultBuilder.Append('ñ'); break;
                    case 0xf2: resultBuilder.Append('ò'); break;
                    case 0xf3: resultBuilder.Append('ó'); break;
                    case 0xf6: resultBuilder.Append('ö'); break;
                    case 0xfa: resultBuilder.Append('ù'); break;
                    case 0xfb: resultBuilder.Append('û'); break;
                    case 0xfc: resultBuilder.Append('ü'); break;
                    default:
                        throw new NotImplementedException(String.Format("0x{0:X2}", preprocessed[i]));
                }
            }

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