"use strict";

function _classCallCheck(instance, Constructor) {
  if (!(instance instanceof Constructor)) {
    throw new TypeError("Cannot call a class as a function");
  }
}

var awsProvider = require("./providers/aws");
var s3CompatibleProvider = require("./providers/s3compatible");
var b2Provider = require("./providers/b2");
var digitalOceanProvider = require("./providers/digitalocean");
var wasabiProvider = require("./providers/wasabi");
var gcsProvider = require("./providers/gcs");
var azureProvider = require("./providers/azure");
var rackspaceProvider = require("./providers/rackspace");
var folderProvider = require("./providers/folder");

var SolidBucket = function SolidBucket(provider, options) {
  _classCallCheck(this, SolidBucket);

  if (provider === "aws") {
    if (!options.accessKeyId || !options.secretAccessKey) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return awsProvider.getAWS(options);
  } else if (provider === "digitalocean") {
    if (!options.accessKeyId || !options.secretAccessKey) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return digitalOceanProvider.getDigitalOcean(options);
  } else if (provider === "wasabi") {
    if (!options.accessKeyId || !options.secretAccessKey) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return wasabiProvider.getWasabi(options);
  } else if (provider === "gcs") {
    if (!options.keyFilename) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return gcsProvider.getGCS(options);
  } else if (provider === "azure") {
    if (!options.accountName || !options.accountKey) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return azureProvider.getAZURE(options);
  } else if (provider === "rackspace") {
    if (!options.username || !options.apiKey) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return rackspaceProvider.getRACKSPACE(options);
  } else if (provider === "s3compatible") {
    if (!options.accessKeyId || !options.secretAccessKey || !options.endpoint) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return s3CompatibleProvider.getS3Compatible(options);
  } else if (provider === "b2") {
    if (!options.accountId || !options.applicationKey) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return b2Provider.getB2(options);
  } else if (provider === "folder") {
    if (!options.folderPath) {
      throw new Error({
        status: 400,
        message: "Missing Auth options"
      });
    }
    return folderProvider.getRootFolder(options);
  } else {
    throw new Error({
      status: 400,
      message: "Missing Auth options"
    });
  }
};

module.exports = SolidBucket;
