// Created with MonoDevelop
//
//    Copyright (C) 2022 Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.



using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Xml;

namespace Hiperscan.Common.IO
{
    public partial class XmlObject
    {
        private const string CULTURE_ATTRIBUTE = "Culture";
        private const string NULL = "null";

        public XmlObject()
        {
        }

        private void Init()
        {
            this.Culture = new CultureInfo("en-US");
            this.Document = null;
            this.DeserializationObject = new Dictionary<string, object>();
        }

        private bool IsIEnumerable(PropertyInfo property_info)
        {
            if (typeof(IEnumerable).IsAssignableFrom(property_info.PropertyType) && property_info.PropertyType != typeof(string))
                return true;

            return false;
        }

        private bool XmlNodeHasTrueChildren(XmlNode node)
        {
            if (node.HasChildNodes == false)
                return false;

            if (node.ChildNodes.Count == 1)
            {
                if (node.ChildNodes[0].NodeType != XmlNodeType.Element)
                    return false;
            }

            return true;
        }

        public bool IsFlagEnum(Type type)
        {
            if (type.IsEnum == false)
                return false;

            return type.GetCustomAttribute(typeof(FlagsAttribute)) != null;
        }

        private object CreateInstance(Type type)
        {
            return Activator.CreateInstance(type, true);
        }

        private void SetFileName(string file_name)
        {
            this.FileName = Path.ChangeExtension(file_name, "xml");
        }

        private XmlDocument Document { get; set; }
        private string FileName { get; set; }
        private BindingFlags BindingFlages { get; set; } = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
        private CultureInfo Culture { get; set; }
    }
}
