using Cloud_Manager;
using Cloud_Manager.Models.ClientContractModels;
using Cloud_Manager.Models.Enums;
using Cloud_Manager.Models.Interfaces;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace Cloud_Manager.Services
{
public class ConnectionService : IConnectionService
{
private readonly BiskilogContext m_context;
private readonly IConfiguration m_configuration;
public ConnectionService(BiskilogContext a_context, IConfiguration configuration)
{
m_context = a_context;
m_configuration = configuration;
}
///
/// Prepares and returns the connection string for a client using the specified database id
///
/// Specified database id to use
///
public string GetClientConnectionString(int a_databaseId)
{
Databasemap? dbMap = m_context.Databasemaps.Find(a_databaseId);
if (dbMap != null)
{
string rawConString = m_configuration.GetConnectionString("PrivateConnection")!.ToString();
return string.Format(rawConString, dbMap.Domain, dbMap.DbName);
}
return ConnectionEnums.ConnectionNotEstablished.ToString();
}
///
/// Prepare the DB context from the specified connection string
///
///
///
/// A configured BiskAcdbContext
public object PrepareDBContext(string a_connectionString)
{
throw new NotImplementedException();
//DbContextOptionsBuilder acdbContext = new DbContextOptionsBuilder();
//acdbContext.UseMySql(a_connectionString, new MariaDbServerVersion(new Version()));
//return new BiskAcdbContext(acdbContext.Options);
}
}
}