using e_suite.API.Common.models;
using e_suite.Database.Audit;
using e_suite.Database.Core.Models;
using e_suite.Service.SigmaImporter.Extensions;
using eSuite.Core.Miscellaneous;

namespace e_suite.Service.SigmaImporter.PrintSpecifications;

public partial class PrintSpecificationImporter
{
    private static readonly Guid SigmaOrganisationGuid = new("c856858e-4ea9-484e-8110-73579f72dba2");
    private readonly GeneralIdRef _sigmaOrganisationGeneralRefId = SigmaOrganisationGuid.ToGeneralIdRef();

    private async Task MakeSureSigmaOrganisationExists(AuditUserDetails auditUserDetails)
    {
        var organisation = await _organisationsManager.GetOrganisation(_sigmaOrganisationGeneralRefId, CancellationToken.None);

        if (organisation == null)
        {
            var addOrganisationDto = new CreateOrganisation
            {
                Name = "Sigma",
                Guid = SigmaOrganisationGuid,
                Address = "n/a",
                Status = OrganisationStatus.Active
            };
            
            await _organisationsManager.AddOrganisation(auditUserDetails, addOrganisationDto, false, CancellationToken.None);
        }
    }
}