/// <summary>
        /// Creates the report.
        /// </summary>
        /// <param name="reportFacility">the result of a DPoW validation to be transformed into report form.</param>
        /// <param name="destinationStream">target stream for the spreadsheet</param>
        /// <param name="format">determines the excel format to use</param>
        /// <returns>true if successful, errors are cought and passed to Logger</returns>
        public bool Create(Facility reportFacility, Stream destinationStream, SpreadSheetFormat format)
        {
            var workBook = format == SpreadSheetFormat.Xlsx
                           // ReSharper disable once RedundantCast
                ? (IWorkbook) new XSSFWorkbook()
                           // ReSharper disable once RedundantCast
                : (IWorkbook) new HSSFWorkbook();


            var facReport = new FacilityReport(reportFacility);


            var summaryPage = workBook.CreateSheet("Summary");

            if (!CreateSummarySheet(summaryPage, reportFacility))
            {
                return(false);
            }

            // reports on Documents
            //
            if (reportFacility.Documents != null)
            {
                var documentsPage = workBook.CreateSheet("Documents");
                if (!CreateDocumentDetailsSheet(documentsPage, reportFacility.Documents))
                {
                    return(false);
                }
            }

            var iRunningWorkBook = 1;

            // reports on AssetTypes details
            //
            // ReSharper disable once LoopCanBeConvertedToQuery // might restore once code is stable
            foreach (var assetType in facReport.AssetRequirementGroups)
            {
                // only report items with any assets submitted (a different report should probably be provided otherwise)

                if (assetType.GetSubmittedAssetsCount() < 1)
                {
                    continue;
                }
                var firstOrDefault = assetType.RequirementCategories.FirstOrDefault(cat => cat.Classification == @"Uniclass2015");
                if (firstOrDefault == null)
                {
                    continue;
                }
                var tName     = firstOrDefault.Code;
                var validName = WorkbookUtil.CreateSafeSheetName(string.Format(@"{0} {1}", iRunningWorkBook++, tName));

                var detailPage = workBook.CreateSheet(validName);
                if (!CreateDetailSheet(detailPage, assetType))
                {
                    return(false);
                }
            }

            // reports on Zones details

            // ReSharper disable once LoopCanBeConvertedToQuery // might restore once code is stable
            foreach (var zoneGroup in facReport.ZoneRequirementGroups)
            {
                // only report items with any assets submitted (a different report should probably be provided otherwise)
                if (zoneGroup.GetSubmittedAssetsCount() < 1)
                {
                    continue;
                }
                var firstOrDefault = zoneGroup.RequirementCategories.FirstOrDefault(cat => cat.Classification == @"Uniclass2015");
                if (firstOrDefault == null)
                {
                    continue;
                }
                var tName     = firstOrDefault.Code;
                var validName = WorkbookUtil.CreateSafeSheetName(string.Format(@"{0} {1}", iRunningWorkBook++, tName));

                var detailPage = workBook.CreateSheet(validName);
                if (!CreateDetailSheet(detailPage, zoneGroup))
                {
                    return(false);
                }
            }
            try
            {
                workBook.Write(destinationStream);
            }
            catch (Exception e)
            {
                Logger.ErrorFormat("Failed to stream excel report: {1}", e.Message);
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Creates the report.
        /// </summary>
        /// <param name="reportFacility">the result of a DPoW validation to be transformed into report form.</param>
        /// <param name="destinationStream">target stream for the spreadsheet</param>
        /// <param name="format">determines the excel format to use</param>
        /// <returns>true if successful, errors are cought and passed to Logger</returns>
        public bool Create(Facility reportFacility, Stream destinationStream, SpreadSheetFormat format)
        {
            var workBook = format == SpreadSheetFormat.Xlsx
                // ReSharper disable once RedundantCast
                ? (IWorkbook)new XSSFWorkbook()
                // ReSharper disable once RedundantCast
                : (IWorkbook)new HSSFWorkbook();
            

            var facReport = new FacilityReport(reportFacility);

            
            var summaryPage = workBook.CreateSheet("Summary");
            if (!CreateSummarySheet(summaryPage, reportFacility)) 
                return false;
            
            // reports on Documents
            //
            if (reportFacility.Documents != null)
            {
                var documentsPage = workBook.CreateSheet("Documents");
                if (!CreateDocumentDetailsSheet(documentsPage, reportFacility.Documents))
                    return false;
            }

            var iRunningWorkBook = 1;
            // reports on AssetTypes details
            //
            // ReSharper disable once LoopCanBeConvertedToQuery // might restore once code is stable
            foreach (var assetType in facReport.AssetRequirementGroups)
            {
                // only report items with any assets submitted (a different report should probably be provided otherwise)

                if (assetType.GetSubmittedAssetsCount() < 1)
                    continue;
                var firstOrDefault = assetType.RequirementCategories.FirstOrDefault(cat => cat.Classification == @"Uniclass2015");
                if (firstOrDefault == null) 
                    continue;
                var tName = firstOrDefault.Code;
                var validName = WorkbookUtil.CreateSafeSheetName(string.Format(@"{0} {1}", iRunningWorkBook++, tName));

                var detailPage = workBook.CreateSheet(validName);
                if (!CreateDetailSheet(detailPage, assetType))
                    return false;
            }

            // reports on Zones details

            // ReSharper disable once LoopCanBeConvertedToQuery // might restore once code is stable
            foreach (var zoneGroup in facReport.ZoneRequirementGroups)
            {
                // only report items with any assets submitted (a different report should probably be provided otherwise)
                if (zoneGroup.GetSubmittedAssetsCount() < 1)
                    continue;
                var firstOrDefault = zoneGroup.RequirementCategories.FirstOrDefault(cat => cat.Classification == @"Uniclass2015");
                if (firstOrDefault == null) 
                    continue;
                var tName = firstOrDefault.Code;
                var validName = WorkbookUtil.CreateSafeSheetName(string.Format(@"{0} {1}", iRunningWorkBook++, tName));

                var detailPage = workBook.CreateSheet(validName);
                if (!CreateDetailSheet(detailPage, zoneGroup))
                    return false;
            }
            try
            {
                workBook.Write(destinationStream);
            }
            catch (Exception e)
            {
                Logger.ErrorFormat("Failed to stream excel report: {1}", e.Message);
                return false;
            }
            return true;
        }