using System.Collections.Generic;
using System.Linq;

namespace ZionRobot.Persistence
{
    public class Queues
    {
        private List<Models.Items.File> files;
        private List<Models.Items.File> extraction;
        private List<Models.Items.File> exportation;
        private Models.Items.File exportated;

        internal List<Models.Items.File> Files
        {
            get
            {
                if (files == null)
                    files = new List<Models.Items.File>();

                files.RemoveAll(file => !System.IO.File.Exists(file.FullPath));

                files.Where(file => file.Status == Persistence.Basic.INTEGRATED && file.Disposed == false)
                    .ToList().ForEach(file =>
                    {

                        file.Dispose();
                    });

                return files;
            }
        }

        internal List<Models.Items.File> Extraction
        {
            get
            {
                if (Files == null)
                    return null;
                
                extraction = Files.Where(x => x.Status == Basic.EXTRACTION).ToList();
                return extraction;
            }
        }

        internal List<Models.Items.File> Integration
        {
            get
            {
                if (Files == null)
                    return null;

                exportation = Files.Where(x => x.Status == Basic.INTEGRATION).ToList();
                return exportation;
            }
        }

        internal Models.Items.File Integrated
        {
            get
            {
                if (Files == null)
                    return null;

                exportated = Files.Where(x => x.Status == Basic.INTEGRATED)?.FirstOrDefault();
                return exportated;
            }
        }
    }
}
