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

namespace TwoMbit
{
    public class Settings
    {
        static List<Settings> list = null;
        public enum Type { STR, DEC, BIN, HEX };

        public int data, init, limit, type;
        public string name, desc, str_data, str_init;
        public bool saveable;

        public Settings(string _name, string _desc, int _data, int _type, int _limit = 0)
        {
            name    = _name;
            desc    = _desc;
            data    = _data;
            init    = _data;	//default
            type    = _type;
            limit   = _limit;
            saveable = true;

            listSetting();
        }

        public Settings(string _name, string _desc, string _data)
        {
            name		= _name;
            desc		= _desc;
            str_data	= _data;
            str_init	= _data;	//default
            type        = (int)Type.STR;
            saveable = true;

            listSetting();
        }

        public Settings(string _name, int _data) //not saveable
        {
            name = _name;
            data = _data;
            init = _data;	//default
            saveable = false;

            listSetting();
        }

        public static List<Settings> getList()
        {
            return list;
        }

        void listSetting()
        {
            if (list == null) {
                list = new List<Settings>();
            }
            list.Add(this);
        }
        
        public static bool operator == (Settings setting, string data)
        {
	        if (setting.str_data == data) return true;
	        return false;
        }

        public static bool operator == (Settings setting, int data)
        {
            if (setting.data == data) return true;
            return false;
        }

        public static bool operator != (Settings setting, string data)
        {
            if (setting.str_data != data) return true;
            return false;
        }

        public static bool operator != (Settings setting, int data)
        {
            if (setting.data != data) return true;
            return false;
        }

        public override bool Equals(object obj)
        {
            return (obj is Settings) && (this == (Settings)obj);
        }

        public override int GetHashCode()
        {
            return 0;
        }
        
        public void toggle()
        {
            data ^= 1;
        }

        public int set_init()
        {
            data = init;
            return init;
        }
    }
}
