var exec = require("cordova/exec");

var SDWebImage = function(){};

SDWebImage.prototype.CONSTANTS = {
	/**
	 * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying.
     * This flag disable this blacklisting.
     */
    SDWebImageRetryFailed: 1 << 0,

    /**
     * By default, image downloads are started during UI interactions, this flags disable this feature,
     * leading to delayed download on UIScrollView deceleration for instance.
     */
    SDWebImageLowPriority: 1 << 1,

    /**
     * This flag disables on-disk caching
     */
    SDWebImageCacheMemoryOnly: 1 << 2,

    /**
     * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
     * By default, the image is only displayed once completely downloaded.
     */
    SDWebImageProgressiveDownload: 1 << 3,

    /**
     * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
     * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.
     * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
     * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
     *
     * Use this flag only if you can't make your URLs static with embeded cache busting parameter.
     */
    SDWebImageRefreshCached: 1 << 4,

    /**
     * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
     * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
     */
    SDWebImageContinueInBackground: 1 << 5,

    /**
     * Handles cookies stored in NSHTTPCookieStore by setting
     * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
     */
    SDWebImageHandleCookies: 1 << 6,

    /**
     * Enable to allow untrusted SSL ceriticates.
     * Useful for testing purposes. Use with caution in production.
     */
    SDWebImageAllowInvalidSSLCertificates: 1 << 7,

    /**
     * By default, image are loaded in the order they were queued. This flag move them to
     * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which
     * could take a while).
     */
    SDWebImageHighPriority: 1 << 8,

    /**
     * By default, placeholder images are loaded while the image is loading. This flag will delay the loading
     * of the placeholder image until after the image has finished loading.
     */
    SDWebImageDelayPlaceholder: 1 << 9

};

SDWebImage.prototype.getImage = function (options, success, error) {
    exec(success, error, "CDVSDWebImage", "getImage", [options]);
};

SDWebImage.prototype.clearCache = function (success, error) {
    exec(success, error, "CDVSDWebImage", "clearCache", []);
};

SDWebImage.prototype.getCacheInfo = function (success, error) {
    exec(success, error, "CDVSDWebImage", "getCacheInfo", []);
};

SDWebImage.prototype.prefetchURLs = function (urls, success, error) {
    exec(success, error, "CDVSDWebImage", "prefetchURLs", urls);
};

SDWebImage.prototype.init = function(options) {
    options = options || {};
};





/*
var options = {
  src: 'http://odl.synchronized.tv.s3.amazonaws.com/images/contributors/simondronet-cover.jpg',
  quality: 90,
  downloadOptions: SDWebImage.CONSTANTS.SDWebImageCacheMemoryOnly
};

SDWebImage.getImage(options, function() {
  console.log('success', arguments);
}, function() {
  console.log('error', arguments);
})
*/
module.exports = new SDWebImage();
