/*
 * 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 "YSSDWebImageOptionsProcessor.h"

@interface YSSDWebImageOptionsResult ()

@property (nonatomic, assign) YSSDWebImageOptions options;
@property (nonatomic, copy, nullable) YSSDWebImageContext *context;

@end

@implementation YSSDWebImageOptionsResult

- (instancetype)initWithOptions:(YSSDWebImageOptions)options context:(YSSDWebImageContext *)context {
    self = [super init];
    if (self) {
        self.options = options;
        self.context = context;
    }
    return self;
}

@end

@interface YSSDWebImageOptionsProcessor ()

@property (nonatomic, copy, nonnull) YSSDWebImageOptionsProcessorBlock block;

@end

@implementation YSSDWebImageOptionsProcessor

- (instancetype)initWithBlock:(YSSDWebImageOptionsProcessorBlock)block {
    self = [super init];
    if (self) {
        self.block = block;
    }
    return self;
}

+ (instancetype)optionsProcessorWithBlock:(YSSDWebImageOptionsProcessorBlock)block {
    YSSDWebImageOptionsProcessor *optionsProcessor = [[YSSDWebImageOptionsProcessor alloc] initWithBlock:block];
    return optionsProcessor;
}

- (YSSDWebImageOptionsResult *)processedResultForURL:(NSURL *)url options:(YSSDWebImageOptions)options context:(YSSDWebImageContext *)context {
    if (!self.block) {
        return nil;
    }
    return self.block(url, options, context);
}

@end
