LocalGovIMS_localgov-ims/src/Admin/Classes/Commands/FileImport/ProcessCommand.cs
using BusinessLogic.Interfaces.Services;
using BusinessLogic.Models.Import;
using log4net;
using System;

namespace Admin.Classes.Commands.FileImport
{
    public class ProcessCommand : BaseCommand<int>
    {
        private readonly IFileImportService _fileImportService;

        public ProcessCommand(ILog log
            , IFileImportService fileImportService
            )
            : base(log)
        {
            _fileImportService = fileImportService ?? throw new ArgumentNullException("fileImportService");
        }

        protected override CommandResult OnExecute(int importId)
        {
            try
            {
                var result = _fileImportService.Process(importId);

                if(!result.Success)
                {
                    return new CommandResult(false, result.Error)
                    {
                        Data = (ProcessResult)result.Data
                    };
                }

                return new CommandResult(true, "File processed successfully.")
                {
                    Data = (ProcessResult)result.Data
                };

            }
            catch (Exception ex)
            {
                return new CommandResult(false, ex.Message);
            }
        }
    }
}