/*
 * This file is part of the YSSDWebImage package.
 * (c) Olivier Poitrey <rs@dailymotion.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

#import "UIImageView+YSWebCache.h"
#import "objc/runtime.h"
#import "UIView+YSWebCacheOperation.h"
#import "UIView+YSWebCache.h"

@implementation UIImageView (YSWebCache)

- (void)yssd_setImageWithURL:(nullable NSURL *)url {
    [self yssd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
}

- (void)yssd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder {
    [self yssd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
}

- (void)yssd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(YSSDWebImageOptions)options {
    [self yssd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
}

- (void)yssd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(YSSDWebImageOptions)options context:(nullable YSSDWebImageContext *)context {
    [self yssd_setImageWithURL:url placeholderImage:placeholder options:options context:context progress:nil completed:nil];
}

- (void)yssd_setImageWithURL:(nullable NSURL *)url completed:(nullable YSSDExternalCompletionBlock)completedBlock {
    [self yssd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
}

- (void)yssd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder completed:(nullable YSSDExternalCompletionBlock)completedBlock {
    [self yssd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
}

- (void)yssd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(YSSDWebImageOptions)options completed:(nullable YSSDExternalCompletionBlock)completedBlock {
    [self yssd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
}

- (void)yssd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(YSSDWebImageOptions)options progress:(nullable YSSDImageLoaderProgressBlock)progressBlock completed:(nullable YSSDExternalCompletionBlock)completedBlock {
    [self yssd_setImageWithURL:url placeholderImage:placeholder options:options context:nil progress:progressBlock completed:completedBlock];
}

- (void)yssd_setImageWithURL:(nullable NSURL *)url
          placeholderImage:(nullable UIImage *)placeholder
                   options:(YSSDWebImageOptions)options
                   context:(nullable YSSDWebImageContext *)context
                  progress:(nullable YSSDImageLoaderProgressBlock)progressBlock
                 completed:(nullable YSSDExternalCompletionBlock)completedBlock {
    [self yssd_internalSetImageWithURL:url
                    placeholderImage:placeholder
                             options:options
                             context:context
                       setImageBlock:nil
                            progress:progressBlock
                           completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, YSSDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
                               if (completedBlock) {
                                   completedBlock(image, error, cacheType, imageURL);
                               }
                           }];
}

@end
