using GB5Shared.DTO.Framework.Login; using GB5Shared.GB5Exception; using GB5Shared.QueueReader; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using PayRollDAL.DTO.EmployeeAttachmentImport; using System; using System.IO; using System.Threading.Tasks; namespace PayRollBLL.EmployeeAttachmentImport { public class EmployeeAttachmentImportBLL : IEmployeeAttachmentImportBLL { public const string MessageType = "EMPLOYEE_ATTACHMENT_BULK_IMPORT"; private readonly IJobQueueEnqueuer _jobQueueEnqueuer; private readonly IConfiguration _configuration; public EmployeeAttachmentImportBLL( IJobQueueEnqueuer jobQueueEnqueuer, IConfiguration configuration) { _jobQueueEnqueuer = jobQueueEnqueuer; _configuration = configuration; } // GB4 parity: EmployeeToUserBulkImportAsynchImport — validates the manifest file // exists under the AttachmentFolder before enqueueing, then returns immediately. public async Task AttachmentBulkImportAsynch(string FileName, int IsSkip, LoginDTO LoginDTO) { if (string.IsNullOrWhiteSpace(FileName)) throw new NotFoundException("FileName to be given for import.."); string manifestPath = GetManifestPath(FileName); if (!File.Exists(manifestPath)) throw new NotFoundException($"File not found in path: {manifestPath}"); var jobDTO = new EmployeeAttachmentBulkImportJobDTO { FileName = FileName, IsSkip = IsSkip }; await _jobQueueEnqueuer.EnqueueAsync(MessageType, JsonConvert.SerializeObject(jobDTO), LoginDTO); return $"Request accepted. After process mail will be sent to {LoginDTO.UserPrimaryMailId}"; } // GB4 parity: gserverpath = ReadValueFromCommonConfig("LogPath") + "/AttachmentFolder/". // Shared with EmployeeAttachmentBulkImportJobHandler — kept internal so both agree on the folder. internal static string GetManifestPath(IConfiguration configuration, string fileName) { string logPath = configuration["LogPath"] ?? Path.Combine(Path.GetTempPath(), "GB5"); string folder = Path.Combine(logPath, "AttachmentFolder"); Directory.CreateDirectory(folder); return Path.Combine(folder, fileName); } private string GetManifestPath(string fileName) => GetManifestPath(_configuration, fileName); } }