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

namespace Edge.Core.Configuration
{
    public enum ConfigValueType
    {
        // most likely the json or xml content.
        PlainText,
        // saved as base 64 string for binary.
        File
    }
    public class ConfigDescription
    {
        /// <summary>
        /// Unique id for a config.
        /// </summary>
        public Guid ConfigId { get; set; }

        /// <summary>
        /// the owner id of the config, could be a BusinessUnit Guid or Device's SerialNumber
        /// </summary>
        public string OwnerId { get; set; }

        /// <summary>
        /// the type of the config
        /// </summary>
        public ConfigValueType ValueType { get; set; }

        /// <summary>
        /// Name of the config
        /// </summary>
        public string Name { get; set; }

        public bool Enabled { get; set; }

        /// <summary>
        /// user friendly message for help understand the purpose of this config
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// Created server time
        /// </summary>
        public DateTime CreatedTime { get; set; }

        public IEnumerable<ConfigFileDescription> ConfigFileDescriptions { get; set; }

        /// <summary>
        /// MD5 hash for concrete config value, used to detect if a config had been changed.
        /// </summary>
        public string ValueMD5 { get; set; }

        public string GroupName { get; set; }
    }

    public class ConfigFileDescription
    {
        public Guid Id { get; set; }

        public virtual string Name { get; set; }

        /// <summary>
        /// Original full file name, like abcd.txt
        /// </summary>
        public virtual string FullName { get; set; }

        public virtual long Length { get; set; }

        public virtual string ContentHash { get; set; }

        public DateTime CreatedServerTime { get; set; }
    }

    public class Configuration
    {
        public Guid Id { get; set; }

        /// <summary>
        /// Gets or sets the owner id who owns this configuration value.
        /// could be a Device, or a BusinessUnit, then this value could be a DeviceSerialNumber, or a BU's guid.
        /// </summary>
        public string OwnerId { get; set; }

        public ConfigValueType ValueType { get; set; }

        /// <summary>
        /// Gets or sets the name of this configuration, unique for each Owner
        /// </summary>
        public string Name { get; set; }

        public virtual Guid? GroupId { get; set; }

        public string Description { get; set; }

        /// <summary>
        /// Gets or sets if enable this configuration.
        /// </summary>
        public bool Enabled { get; set; }

        /// <summary>
        /// --!!!!!!---> IF xml content, make sure no space between nodes
        /// Gets or sets the concreate configuration values,
        /// Use base64 encode string for faciliates the binary content.
        /// or json(xml) for other cases.
        /// </summary>
        public string Value { get; set; }

        public virtual List<ConfigurationFile> Files { get; set; }

        public DateTime CreatedServerTime { get; set; }
        public virtual Guid CreatedByUser { get; set; }
    }

    public class ConfigurationFile
    {
        public Guid Id { get; set; }

        public virtual Guid ConfigurationId { get; set; }
        public virtual Configuration Configuration { get; set; }

        public virtual string Name { get; set; }

        /// <summary>
        /// Original full file name, like abcd.txt
        /// </summary>
        public virtual string FullName { get; set; }

        public virtual long Length { get; set; }

        public virtual string ContentHash { get; set; }

        public virtual byte[] Value { get; set; }

        public DateTime CreatedServerTime { get; set; }
    }
}
