//
//  SBRScriptPolicy.h
//  App
//
//  Created by James Magahern on 10/15/21.
//

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>

NS_ASSUME_NONNULL_BEGIN

@class UIImage, UIColor;

typedef NS_ENUM(NSInteger, SBRScriptOriginPolicyType) {
    SBRScriptOriginPolicyTypeAlpha,
    SBRScriptOriginPolicyTypeBravo,
    SBRScriptOriginPolicyTypeCharlie,
    SBRScriptOriginPolicyTypeDelta,
    SBRScriptOriginPolicyTypeEcho,
} NS_SWIFT_NAME(ScriptPolicy.PolicyType);

NS_SWIFT_NAME(ScriptPolicy.IconConfiguration)
@interface SBRScriptPolicyIconConfiguration : NSObject
@property (nonatomic, readwrite) CGSize size;
@property (nonatomic, strong, nullable) UIColor *foregroundColor;
@property (nonatomic, strong, nullable) UIColor *backgroundColor;

- (instancetype)initWithSize:(CGSize)size foregroundColor:(nullable UIColor *)foregroundColor backgroundColor:(nullable UIColor *)backgroundColor;
@end

NS_SWIFT_NAME(ScriptPolicy)
@interface SBRScriptPolicy : NSObject <NSSecureCoding>
@property (nonatomic, copy) NSString *origin;
@property (nonatomic, readwrite) SBRScriptOriginPolicyType policyType;

+ (NSString *)titleForPolicyType:(SBRScriptOriginPolicyType)policyType
    NS_SWIFT_NAME(title(forPolicyType:));

+ (NSString *)localizedDescriptionForPolicyType:(SBRScriptOriginPolicyType)policyType
    NS_SWIFT_NAME(localizedDescription(forPolicyType:));

+ (UIImage *)iconRepresentationForPolicyType:(SBRScriptOriginPolicyType)policyType withConfiguration:(SBRScriptPolicyIconConfiguration *)configuration
    NS_SWIFT_NAME(iconRepresentation(forPolicyType:configuration:));

- (instancetype)initWithSecurityOrigin:(NSString *)origin policyType:(SBRScriptOriginPolicyType)policyType;

/// Returns YES if policy type allows embedded (<script>) JavaScript for the given origin. 
- (BOOL)allowsEmbeddedJavaScript;

/// Returns YES if policy allows loading external JavaScript resource with the security origin `resourceOrigin`. 
- (BOOL)allowsExternalJavaScriptResourceOrigin:(NSString *)resourceOrigin;

- (instancetype)init NS_UNAVAILABLE;
@end

NS_ASSUME_NONNULL_END
