using AutoMapper;
using DocumentFormat.OpenXml.InkML;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.DL;

namespace WorkFlowCheck.BL.Services
{
    public class SystemService : ISystemService
    {
        public readonly AppDbContext _dbContext;
        public readonly IMapper _mapper;
        public readonly IConfiguration _config;
        public SystemService(AppDbContext dbContext,
                           IMapper mapper,
                           IConfiguration configuration)
        {
            _config = configuration;
            _dbContext = dbContext;
            _mapper = mapper;
        }
        public async Task<string> GetDatabaseAndVersionInfoAsync()
        {
            var retVal = "";
            var connection = _dbContext.Database.GetDbConnection();
            var typeName = connection.GetType().Name;

            //if (typeName.Contains("Npgsql"))
            //{
            //    var builder = new NpgsqlConnectionStringBuilder(connection.ConnectionString);
            //    retVal= builder.Database;
            //}
            
            if (typeName.Contains("SqlConnection"))
            {
                var builder = new SqlConnectionStringBuilder(connection.ConnectionString);
                retVal= builder.InitialCatalog;
            }
                return retVal;
        }
    }
}
