using Dapper;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace e_suite.Service.SigmaImporter.Repository;

public interface ISigmaRepository
{
    Task<IEnumerable<SigmaDomain>> GetDomains();
}

public class SigmaRepository : MySqlRepositoryBase, ISigmaRepository
{
    public SigmaRepository(IConfiguration configuration, ILogger logger) : base(configuration, logger,"Sigma")
    {
    }

    public async Task<IEnumerable<SigmaDomain>> GetDomains()
    {
        try
        {
            var result = await Connection.QueryAsync<SigmaDomain>(
                "select\r\n    c.company_id as Id,\r\n    c.name as Name,\r\n    c.tla as Tla\r\nfrom live_company as c\r\nINNER JOIN live_odin_servers as os\r\n    ON os.odinID=c.odinserverFK\r\n    and os.version >= 3\r\nwhere c.active = '1'\r\nand c.reports = '1'");
            return result;
        }
        finally
        {
            Close();
        }
    }
}

public class SigmaDomain
{
    public long Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public string Tla { get; set; } = string.Empty;
    public string Hostname { get; set; } = string.Empty;
}