using EgtBEAMWALL.DataLayer.DatabaseModels;
using MySql.Data.EntityFramework;
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.IO;

namespace EgtBEAMWALL.DataLayer
{
    //[DbConfigurationType(typeof(MySqlEFConfiguration))]
    public class aMySqlConfiguration : MySqlEFConfiguration
    {
        #region Public Constructors

        public aMySqlConfiguration() : base()
        {
            var path = Path.GetDirectoryName(this.GetType().Assembly.Location);
            SetModelStore(new DefaultDbModelStore(path));
        }

        #endregion Public Constructors
    }

    [DbConfigurationType(typeof(MySqlEFConfiguration))]
    public class DatabaseContext : DbContext
    {
        #region Public Constructors

        [Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
        public DatabaseContext() : base(DbConfig.CONNECTION_STRING)
        {
        }

        public DatabaseContext(string connectionString) : base(connectionString)
        {
            Database.CreateIfNotExists();
        }

        #endregion Public Constructors

        #region Public Properties

        /// <summary>
        /// BTLParts management
        /// </summary>
        public DbSet<BTLPartModel> BTLPartList { get; set; }

        /// <summary>
        /// Machine Log management
        /// </summary>
        public DbSet<LogMachineModel> LogMachineList { get; set; }

        /// <summary>
        /// Support Log management
        /// </summary>
        public DbSet<LogSupportModel> LogSupportList { get; set; }

        /// <summary>
        /// Parts management
        /// </summary>
        public DbSet<MachGroupModel> MachGroupList { get; set; }

        /// <summary>
        /// Parts management
        /// </summary>
        public DbSet<PartModel> PartList { get; set; }

        /// <summary>
        /// Parts management
        /// </summary>
        public DbSet<ProdModel> ProdList { get; set; }

        /// <summary>
        /// Parts management
        /// </summary>
        public DbSet<ProjModel> ProjList { get; set; }

        /// <summary>
        /// StatusMap management
        /// </summary>
        public DbSet<StatusMapModel> StatusMapList { get; set; }

        #endregion Public Properties

        #region Public Methods

        public static DatabaseContext Create()
        {
            return new DatabaseContext(DbConfig.CONNECTION_STRING);
        }

        #endregion Public Methods
    }
}