using System;
using AyaNova.Models;

namespace AyaNova.Biz
{

    public class AyaTypeId : System.Object
    {
        private long _id;
        private AyaType _ayaType;

        public long ObjectId
        {
            get
            {
                return _id;
            }
        }

        public AyaType ObjectType
        {
            get
            {
                return _ayaType;
            }
        }

        public int ObjectTypeAsInt
        {
            get
            {
                return (int)_ayaType;
            }
        }

        public AyaTypeId(AyaType ObjectType, long Id)
        {
            _id = Id;
            _ayaType = ObjectType;
        }

        public AyaTypeId(string sObjectTypeNumeral, string sId)
        {
            _id = long.Parse(sId);
            int nType = int.Parse(sObjectTypeNumeral);
            if (!AyaTypeExists(nType))
                _ayaType = AyaType.NoType;
            else
                _ayaType = (AyaType)Enum.Parse(typeof(AyaType), sObjectTypeNumeral);
        }

        public bool Equals(AyaTypeId x, AyaTypeId y)
        {

            //Check whether the compared objects reference the same data.
            if (Object.ReferenceEquals(x, y)) return true;

            //Check whether any of the compared objects is null.
            if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                return false;

            //Check whether the products' properties are equal.
            return x.ObjectId == y.ObjectId && x.ObjectType == y.ObjectType;
        }

        public bool IsEmpty
        {
            get
            {
                return (_ayaType == AyaType.NoType) || (_id == 0);
            }
        }

      


        /// <summary>
        /// Check if the numeric or name type value is an actual enum value
        /// </summary>
        /// <param name="enumNumber"></param>
        /// <returns></returns>
        public bool AyaTypeExists(int enumNumber)
        {
            return Enum.IsDefined(typeof(AyaType), enumNumber);
        }


        //Custom attribute checking

        /// <summary>
        /// Is object a core biz object
        /// </summary>
        /// <returns></returns>
        public bool IsCoreBizObject
        {
            get
            {
                return this.ObjectType.HasAttribute(typeof(CoreBizObjectAttribute));
            }
        }





    }//eoc


}//eons 

