// This file was automatically generated by protocompiler
// DO NOT EDIT!
// Compiled from C2Metric.proto

#import "SECC2MPGenericEventMetricValue.h"
#import <ProtocolBuffer/PBConstants.h>
#import <ProtocolBuffer/PBHashUtil.h>
#import <ProtocolBuffer/PBDataReader.h>

#import "SECC2MPError.h"

#if !__has_feature(objc_arc)
# error This generated file depends on ARC but it is not enabled; turn on ARC, or use 'objc_use_arc' option to generate non-ARC code.
#endif

@implementation SECC2MPGenericEventMetricValue

- (BOOL)hasStringValue
{
    return _stringValue != nil;
}
@synthesize stringValue = _stringValue;
@synthesize doubleValue = _doubleValue;
- (void)setDoubleValue:(double)v
{
    _has.doubleValue = YES;
    _doubleValue = v;
}
- (void)setHasDoubleValue:(BOOL)f
{
    _has.doubleValue = f;
}
- (BOOL)hasDoubleValue
{
    return _has.doubleValue;
}
@synthesize dateValue = _dateValue;
- (void)setDateValue:(uint64_t)v
{
    _has.dateValue = YES;
    _dateValue = v;
}
- (void)setHasDateValue:(BOOL)f
{
    _has.dateValue = f;
}
- (BOOL)hasDateValue
{
    return _has.dateValue;
}
- (BOOL)hasErrorValue
{
    return _errorValue != nil;
}
@synthesize errorValue = _errorValue;

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@ %@", [super description], [self dictionaryRepresentation]];
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if (self->_stringValue)
    {
        [dict setObject:self->_stringValue forKey:@"string_value"];
    }
    if (self->_has.doubleValue)
    {
        [dict setObject:[NSNumber numberWithDouble:self->_doubleValue] forKey:@"double_value"];
    }
    if (self->_has.dateValue)
    {
        [dict setObject:[NSNumber numberWithUnsignedLongLong:self->_dateValue] forKey:@"date_value"];
    }
    if (self->_errorValue)
    {
        [dict setObject:[_errorValue dictionaryRepresentation] forKey:@"error_value"];
    }
    return dict;
}

BOOL SECC2MPGenericEventMetricValueReadFrom(__unsafe_unretained SECC2MPGenericEventMetricValue *self, __unsafe_unretained PBDataReader *reader) {
    while (PBReaderHasMoreData(reader)) {
        uint32_t tag = 0;
        uint8_t aType = 0;

        PBReaderReadTag32AndType(reader, &tag, &aType);

        if (PBReaderHasError(reader))
            break;

        if (aType == TYPE_END_GROUP) {
            break;
        }

        switch (tag) {

            case 101 /* stringValue */:
            {
                NSString *new_stringValue = PBReaderReadString(reader);
                self->_stringValue = new_stringValue;
            }
            break;
            case 102 /* doubleValue */:
            {
                self->_has.doubleValue = YES;
                self->_doubleValue = PBReaderReadDouble(reader);
            }
            break;
            case 103 /* dateValue */:
            {
                self->_has.dateValue = YES;
                self->_dateValue = PBReaderReadUint64(reader);
            }
            break;
            case 201 /* errorValue */:
            {
                SECC2MPError *new_errorValue = [[SECC2MPError alloc] init];
                self->_errorValue = new_errorValue;
                PBDataReaderMark mark_errorValue;
                BOOL markError = !PBReaderPlaceMark(reader, &mark_errorValue);
                if (markError)
                {
                    return NO;
                }
                BOOL inError = !SECC2MPErrorReadFrom(new_errorValue, reader);
                if (inError)
                {
                    return NO;
                }
                PBReaderRecallMark(reader, &mark_errorValue);
            }
            break;
            default:
                if (!PBReaderSkipValueWithTag(reader, tag, aType))
                    return NO;
                break;
        }
    }
    return !PBReaderHasError(reader);
}

- (BOOL)readFrom:(PBDataReader *)reader
{
    return SECC2MPGenericEventMetricValueReadFrom(self, reader);
}
- (void)writeTo:(PBDataWriter *)writer
{
    /* stringValue */
    {
        if (self->_stringValue)
        {
            PBDataWriterWriteStringField(writer, self->_stringValue, 101);
        }
    }
    /* doubleValue */
    {
        if (self->_has.doubleValue)
        {
            PBDataWriterWriteDoubleField(writer, self->_doubleValue, 102);
        }
    }
    /* dateValue */
    {
        if (self->_has.dateValue)
        {
            PBDataWriterWriteUint64Field(writer, self->_dateValue, 103);
        }
    }
    /* errorValue */
    {
        if (self->_errorValue != nil)
        {
            PBDataWriterWriteSubmessage(writer, self->_errorValue, 201);
        }
    }
}

- (void)copyTo:(SECC2MPGenericEventMetricValue *)other
{
    if (_stringValue)
    {
        other.stringValue = _stringValue;
    }
    if (self->_has.doubleValue)
    {
        other->_doubleValue = _doubleValue;
        other->_has.doubleValue = YES;
    }
    if (self->_has.dateValue)
    {
        other->_dateValue = _dateValue;
        other->_has.dateValue = YES;
    }
    if (_errorValue)
    {
        other.errorValue = _errorValue;
    }
}

- (id)copyWithZone:(NSZone *)zone
{
    SECC2MPGenericEventMetricValue *copy = [[[self class] allocWithZone:zone] init];
    copy->_stringValue = [_stringValue copyWithZone:zone];
    if (self->_has.doubleValue)
    {
        copy->_doubleValue = _doubleValue;
        copy->_has.doubleValue = YES;
    }
    if (self->_has.dateValue)
    {
        copy->_dateValue = _dateValue;
        copy->_has.dateValue = YES;
    }
    copy->_errorValue = [_errorValue copyWithZone:zone];
    return copy;
}

- (BOOL)isEqual:(id)object
{
    SECC2MPGenericEventMetricValue *other = (SECC2MPGenericEventMetricValue *)object;
    return [other isMemberOfClass:[self class]]
    &&
    ((!self->_stringValue && !other->_stringValue) || [self->_stringValue isEqual:other->_stringValue])
    &&
    ((self->_has.doubleValue && other->_has.doubleValue && self->_doubleValue == other->_doubleValue) || (!self->_has.doubleValue && !other->_has.doubleValue))
    &&
    ((self->_has.dateValue && other->_has.dateValue && self->_dateValue == other->_dateValue) || (!self->_has.dateValue && !other->_has.dateValue))
    &&
    ((!self->_errorValue && !other->_errorValue) || [self->_errorValue isEqual:other->_errorValue])
    ;
}

- (NSUInteger)hash
{
    return 0
    ^
    [self->_stringValue hash]
    ^
    (self->_has.doubleValue ? PBHashDouble(self->_doubleValue) : 0)
    ^
    (self->_has.dateValue ? PBHashInt((NSUInteger)self->_dateValue) : 0)
    ^
    [self->_errorValue hash]
    ;
}

- (void)mergeFrom:(SECC2MPGenericEventMetricValue *)other
{
    if (other->_stringValue)
    {
        [self setStringValue:other->_stringValue];
    }
    if (other->_has.doubleValue)
    {
        self->_doubleValue = other->_doubleValue;
        self->_has.doubleValue = YES;
    }
    if (other->_has.dateValue)
    {
        self->_dateValue = other->_dateValue;
        self->_has.dateValue = YES;
    }
    if (self->_errorValue && other->_errorValue)
    {
        [self->_errorValue mergeFrom:other->_errorValue];
    }
    else if (!self->_errorValue && other->_errorValue)
    {
        [self setErrorValue:other->_errorValue];
    }
}

@end

