#import <Foundation/Foundation.h>
#import "BarcodeItem.h"

@implementation BarcodeItem

- (instancetype)initWithText:(NSString *)text andType:(SBSDKBarcodeType *)type {
    self = [super init];
    if (self) {
        _text = text;
        _type = type;
    }
    return self;
}

- (BOOL)isEqual:(id)object {
    if (self == object) {
        return YES;
    }
    if (![object isKindOfClass:[BarcodeItem class]]) {
        return NO;
    }
    return [self isEqualToDataClass:(BarcodeItem *)object];
}

- (BOOL)isEqualToDataClass:(BarcodeItem *)other {
    if (!other) {
        return NO;
    }
    
    return [_text isEqualToString:other.text] && [_type isEqual:other.type];
}

- (NSUInteger)hash
{
    return [self.text hash] + [self.type hash];
}

+ (NSString *) uuidFor:(SBSDKBarcodeScannerResult *)barcodeItem {
    return [NSString stringWithFormat:@"%@_%@", barcodeItem.rawTextStringWithExtension, barcodeItem.type.toString];
}

@end
