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

namespace skyscraper5.Skyscraper
{
    public class Hasher
    {
        public static int HashObjects(params object[] objects)
        {
            CRC32 crc32 = new CRC32();
            foreach (object o in objects)
            {
                string name = o.GetType().Name;
                switch (name)
                {
                    case nameof(Int32):
                        crc32.SlurpBlock(BitConverter.GetBytes((int)o), 0, 4);
                        break;
                    case nameof(UInt16):
                        crc32.SlurpBlock(BitConverter.GetBytes((ushort)o), 0, 2);
                        break;
                    case nameof(Byte):
                        crc32.SlurpBlock(new byte[] { (byte)o }, 0, 1);
                        break;
                    case nameof(String):
                        byte[] bytes = Encoding.ASCII.GetBytes(o.ToString());
                        crc32.SlurpBlock(bytes, 0, bytes.Length);
                        break;
                    default:
                        throw new NotImplementedException(name);
                }
            }
            return crc32.Crc32Result;
        }
    }
}
