﻿using appfactum.core;
using Npgsql;

namespace appfactum.postgre
{
    /// <summary>
    /// Configuration for an PostgreSQL database
    /// </summary>
    public class PostgreConfiguration : IConfiguration
    {
        private NpgsqlConnectionStringBuilder _builder = new NpgsqlConnectionStringBuilder();

        public NpgsqlConnectionStringBuilder Builder { get => _builder; }

        public PostgreConfiguration() : base()
        {
            Builder.Host = "localhost";
            Builder.Port = 5432;
            Builder.Username = "SYSDBA";
            Builder.Password = "masterkey";
            Builder.Database = "";

            Builder.Pooling = true;
        }

        public string ConnectionString { get => _builder.ConnectionString; set => _builder.ConnectionString = value; }
        
        /// <summary>
        /// Name der Datenbank
        /// </summary>
        public string DatabaseName { get => _builder.Database; set => _builder.Database = value; }


        /// <summary>
        /// Conflict Handling of the Database
        /// Used for the DataBaseObject.Save method and determines how conflicts are handled.
        /// </summary>
        public eConflictMode ConflictMode { get; set; } = eConflictMode.LastWins;

        /// <summary>
        /// Typ of Database...
        /// </summary>
        public eDatabaseType DatabaseType => eDatabaseType.PostgreSQL;

        /// <summary>
        /// Allow drop columns from table which have no representation in a property of persistent class
        /// </summary>
        public bool AllowDropColumns { get; set; }
    }
}
