using System;
using System.Collections.Generic;
using System.Linq;
using ZionExtractor;
using ZionRobot.Models.Items;
using ZionSchematics;
using ZionVault.Binder.OCR;
using ZionVault.Binder.Output;

namespace ZionRobot.Tasks
{
	// Token: 0x0200001E RID: 30
	internal class Extractor
	{
		// Token: 0x1700002D RID: 45
		// (get) Token: 0x060000AC RID: 172 RVA: 0x000060C0 File Offset: 0x000042C0
		public bool Running
		{
			get
			{
				return this.running;
			}
		}

		// Token: 0x060000AD RID: 173 RVA: 0x000060C8 File Offset: 0x000042C8
		public Extractor()
		{
			this.running = false;
			this.extractor = new Analyzer();
		}

		// Token: 0x060000AE RID: 174 RVA: 0x000060E4 File Offset: 0x000042E4
		public void Execute(File file, List<Schematics> blueprints)
		{
			this.running = true;
			int count = 1;
			using (ZionVault.Binder.OCR.Document ocr = new ZionVault.Binder.OCR.Document(file.OCR, false))
			{
				using (ZionVault.Binder.Output.Document metadata = new ZionVault.Binder.Output.Document())
				{
					int index = 1;
					ocr.Pages.ForEach(delegate(ZionVault.Binder.OCR.Page page)
					{
						foreach (Schematics bprt in blueprints)
						{
							ZionVault.Binder.Output.Page content = this.extractor.Apply(bprt, page);
							bool flag = content == null;
							if (!flag)
							{
								metadata.Pages.Add(content);
								break;
							}
						}
						bool flag2 = (from p in metadata.Pages
						where p.Index == page.Index
						select p).FirstOrDefault<ZionVault.Binder.Output.Page>() == null;
						if (flag2)
						{
							ZionVault.Binder.Output.Page data = new ZionVault.Binder.Output.Page
							{
								Index = page.Index,
								Type = "UNKWON"
							};
							metadata.Pages.Add(data);
						}
						int index;
						metadata.Pages.Last<ZionVault.Binder.Output.Page>().Index = index;
						index = index;
						index++;
						count += metadata.Pages.Count<ZionVault.Binder.Output.Page>();
					});
					metadata.Status = "INTEGRATION";
					metadata.Save(file.META, false, false);
				}
			}
			file.Status = "INTEGRATION";
			this.running = false;
		}

		// Token: 0x0400003A RID: 58
		private bool running;

		// Token: 0x0400003B RID: 59
		private Analyzer extractor;
	}
}
