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

namespace Sdaleo
{
    /// <summary>
    /// Our Custom Database Error Class that DB Functions Return to External Callers
    /// </summary>
    public class DBError
    {        
        public int nError { get; set; }
        public string ErrorMsg { get; set; }
        public ICollection Errors { get; set; }

        public DBError()
        {
            nError = -1;
            ErrorMsg = String.Empty;
            Errors = null;
        }
        public DBError(int nError, string ErrorMsg, ICollection Errors)
        {
            this.nError = nError;
            this.ErrorMsg = ErrorMsg;
            this.Errors = Errors;
        }

        /// <summary>
        /// Used internally to quickly create a custom error object
        /// </summary>
        /// <param name="ErrorMsg">The Error Message to Display</param>
        private const int DATABASE_LAYER_ERROR_NUMBER = 1978;        
        internal static DBError Create(string ErrorMsg)
        {
            return new DBError(DATABASE_LAYER_ERROR_NUMBER, ErrorMsg, null);
        }        

        public bool ErrorOccured { get { return (nError != -1 && !String.IsNullOrEmpty(ErrorMsg)); } }
        public int GetErrorCount { get { if (Errors != null) { return Errors.Count; } return 0; } }
        public List<int> GetAllErrorNumbers
        {
            get
            {
                if (Errors != null)
                {
                    List<int> list = new List<int>();

                    // * DBMS SPECIFIC *
                    // TO DO
                    foreach (SqlError error in Errors)
                        list.Add(error.Number);
                    //

                    return list;
                }
                return null;
            }
        }        
    }
}
