using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;
using skyscraper8.Skyscraper.Scraper.Storage;

namespace skyscraper5.Skyscraper.Scraper.Storage.Filesystem
{
    [SkyscraperPlugin]
    [StorageId(2)]
    [StorageName("Filesystem")]
    public class FilesystemScraperStorageFactory : DataStorageFactory, ObjectStorageFactory
    {
        public string Directory { get; set; }

        public DataStorage CreateDataStorage()
        {
            DirectoryInfo di = new DirectoryInfo(Directory);
            if (!di.Exists)
	            di.EnsureExists();
            return new FilesystemStorage(di);
        }

        public ObjectStorage CreateObjectStorage()
        {
			DirectoryInfo di = new DirectoryInfo(Directory);
			if (!di.Exists)
				di.EnsureExists();
			return new FilesystemStorage(di);
		}

        public bool IsEquivalent(DataStorageFactory dataStorageFactory)
        {
	        FilesystemScraperStorageFactory other = dataStorageFactory as FilesystemScraperStorageFactory;
	        if (other == null)
		        return false;

	        if (!other.Directory.Equals(this.Directory))
		        return false;

	        return true;
        }
    }
}
