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

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

#import "SECC2MPCloudKitInfo.h"
#import "SECC2MPDeviceInfo.h"
#import "SECC2MPGenericEvent.h"
#import "SECC2MPNetworkEvent.h"
#import "SECC2MPServerInfo.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 SECC2MPMetric

@synthesize metricType = _metricType;
- (SECC2MPMetric_Type)metricType
{
    return _has.metricType ? _metricType : SECC2MPMetric_Type_none_type;
}
- (void)setMetricType:(SECC2MPMetric_Type)v
{
    _has.metricType = YES;
    _metricType = v;
}
- (void)setHasMetricType:(BOOL)f
{
    _has.metricType = f;
}
- (BOOL)hasMetricType
{
    return _has.metricType;
}
- (NSString *)metricTypeAsString:(SECC2MPMetric_Type)value
{
    return SECC2MPMetric_TypeAsString(value);
}
- (SECC2MPMetric_Type)StringAsMetricType:(NSString *)str
{
    return StringAsSECC2MPMetric_Type(str);
}
- (BOOL)hasDeviceInfo
{
    return _deviceInfo != nil;
}
@synthesize deviceInfo = _deviceInfo;
- (BOOL)hasCloudkitInfo
{
    return _cloudkitInfo != nil;
}
@synthesize cloudkitInfo = _cloudkitInfo;
- (BOOL)hasServerInfo
{
    return _serverInfo != nil;
}
@synthesize serverInfo = _serverInfo;
@synthesize triggers = _triggers;
- (void)setTriggers:(uint64_t)v
{
    _has.triggers = YES;
    _triggers = v;
}
- (void)setHasTriggers:(BOOL)f
{
    _has.triggers = f;
}
- (BOOL)hasTriggers
{
    return _has.triggers;
}
@synthesize reportFrequency = _reportFrequency;
- (void)setReportFrequency:(uint64_t)v
{
    _has.reportFrequency = YES;
    _reportFrequency = v;
}
- (void)setHasReportFrequency:(BOOL)f
{
    _has.reportFrequency = f;
}
- (BOOL)hasReportFrequency
{
    return _has.reportFrequency;
}
@synthesize reportFrequencyBase = _reportFrequencyBase;
- (void)setReportFrequencyBase:(uint64_t)v
{
    _has.reportFrequencyBase = YES;
    _reportFrequencyBase = v;
}
- (void)setHasReportFrequencyBase:(BOOL)f
{
    _has.reportFrequencyBase = f;
}
- (BOOL)hasReportFrequencyBase
{
    return _has.reportFrequencyBase;
}
- (BOOL)hasNetworkEvent
{
    return _networkEvent != nil;
}
@synthesize networkEvent = _networkEvent;
- (BOOL)hasGenericEvent
{
    return _genericEvent != nil;
}
@synthesize genericEvent = _genericEvent;

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

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if (self->_has.metricType)
    {
        [dict setObject:SECC2MPMetric_TypeAsString(self->_metricType) forKey:@"metric_type"];
    }
    if (self->_deviceInfo)
    {
        [dict setObject:[_deviceInfo dictionaryRepresentation] forKey:@"device_info"];
    }
    if (self->_cloudkitInfo)
    {
        [dict setObject:[_cloudkitInfo dictionaryRepresentation] forKey:@"cloudkit_info"];
    }
    if (self->_serverInfo)
    {
        [dict setObject:[_serverInfo dictionaryRepresentation] forKey:@"server_info"];
    }
    if (self->_has.triggers)
    {
        [dict setObject:[NSNumber numberWithUnsignedLongLong:self->_triggers] forKey:@"triggers"];
    }
    if (self->_has.reportFrequency)
    {
        [dict setObject:[NSNumber numberWithUnsignedLongLong:self->_reportFrequency] forKey:@"report_frequency"];
    }
    if (self->_has.reportFrequencyBase)
    {
        [dict setObject:[NSNumber numberWithUnsignedLongLong:self->_reportFrequencyBase] forKey:@"report_frequency_base"];
    }
    if (self->_networkEvent)
    {
        [dict setObject:[_networkEvent dictionaryRepresentation] forKey:@"network_event"];
    }
    if (self->_genericEvent)
    {
        [dict setObject:[_genericEvent dictionaryRepresentation] forKey:@"generic_event"];
    }
    return dict;
}

BOOL SECC2MPMetricReadFrom(__unsafe_unretained SECC2MPMetric *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 1 /* metricType */:
            {
                self->_has.metricType = YES;
                self->_metricType = PBReaderReadInt32(reader);
            }
            break;
            case 2 /* deviceInfo */:
            {
                SECC2MPDeviceInfo *new_deviceInfo = [[SECC2MPDeviceInfo alloc] init];
                self->_deviceInfo = new_deviceInfo;
                PBDataReaderMark mark_deviceInfo;
                BOOL markError = !PBReaderPlaceMark(reader, &mark_deviceInfo);
                if (markError)
                {
                    return NO;
                }
                BOOL inError = !SECC2MPDeviceInfoReadFrom(new_deviceInfo, reader);
                if (inError)
                {
                    return NO;
                }
                PBReaderRecallMark(reader, &mark_deviceInfo);
            }
            break;
            case 3 /* cloudkitInfo */:
            {
                SECC2MPCloudKitInfo *new_cloudkitInfo = [[SECC2MPCloudKitInfo alloc] init];
                self->_cloudkitInfo = new_cloudkitInfo;
                PBDataReaderMark mark_cloudkitInfo;
                BOOL markError = !PBReaderPlaceMark(reader, &mark_cloudkitInfo);
                if (markError)
                {
                    return NO;
                }
                BOOL inError = !SECC2MPCloudKitInfoReadFrom(new_cloudkitInfo, reader);
                if (inError)
                {
                    return NO;
                }
                PBReaderRecallMark(reader, &mark_cloudkitInfo);
            }
            break;
            case 4 /* serverInfo */:
            {
                SECC2MPServerInfo *new_serverInfo = [[SECC2MPServerInfo alloc] init];
                self->_serverInfo = new_serverInfo;
                PBDataReaderMark mark_serverInfo;
                BOOL markError = !PBReaderPlaceMark(reader, &mark_serverInfo);
                if (markError)
                {
                    return NO;
                }
                BOOL inError = !SECC2MPServerInfoReadFrom(new_serverInfo, reader);
                if (inError)
                {
                    return NO;
                }
                PBReaderRecallMark(reader, &mark_serverInfo);
            }
            break;
            case 100 /* triggers */:
            {
                self->_has.triggers = YES;
                self->_triggers = PBReaderReadUint64(reader);
            }
            break;
            case 101 /* reportFrequency */:
            {
                self->_has.reportFrequency = YES;
                self->_reportFrequency = PBReaderReadUint64(reader);
            }
            break;
            case 102 /* reportFrequencyBase */:
            {
                self->_has.reportFrequencyBase = YES;
                self->_reportFrequencyBase = PBReaderReadUint64(reader);
            }
            break;
            case 200 /* networkEvent */:
            {
                SECC2MPNetworkEvent *new_networkEvent = [[SECC2MPNetworkEvent alloc] init];
                self->_networkEvent = new_networkEvent;
                PBDataReaderMark mark_networkEvent;
                BOOL markError = !PBReaderPlaceMark(reader, &mark_networkEvent);
                if (markError)
                {
                    return NO;
                }
                BOOL inError = !SECC2MPNetworkEventReadFrom(new_networkEvent, reader);
                if (inError)
                {
                    return NO;
                }
                PBReaderRecallMark(reader, &mark_networkEvent);
            }
            break;
            case 201 /* genericEvent */:
            {
                SECC2MPGenericEvent *new_genericEvent = [[SECC2MPGenericEvent alloc] init];
                self->_genericEvent = new_genericEvent;
                PBDataReaderMark mark_genericEvent;
                BOOL markError = !PBReaderPlaceMark(reader, &mark_genericEvent);
                if (markError)
                {
                    return NO;
                }
                BOOL inError = !SECC2MPGenericEventReadFrom(new_genericEvent, reader);
                if (inError)
                {
                    return NO;
                }
                PBReaderRecallMark(reader, &mark_genericEvent);
            }
            break;
            default:
                if (!PBReaderSkipValueWithTag(reader, tag, aType))
                    return NO;
                break;
        }
    }
    return !PBReaderHasError(reader);
}

- (BOOL)readFrom:(PBDataReader *)reader
{
    return SECC2MPMetricReadFrom(self, reader);
}
- (void)writeTo:(PBDataWriter *)writer
{
    /* metricType */
    {
        if (self->_has.metricType)
        {
            PBDataWriterWriteInt32Field(writer, self->_metricType, 1);
        }
    }
    /* deviceInfo */
    {
        if (self->_deviceInfo != nil)
        {
            PBDataWriterWriteSubmessage(writer, self->_deviceInfo, 2);
        }
    }
    /* cloudkitInfo */
    {
        if (self->_cloudkitInfo != nil)
        {
            PBDataWriterWriteSubmessage(writer, self->_cloudkitInfo, 3);
        }
    }
    /* serverInfo */
    {
        if (self->_serverInfo != nil)
        {
            PBDataWriterWriteSubmessage(writer, self->_serverInfo, 4);
        }
    }
    /* triggers */
    {
        if (self->_has.triggers)
        {
            PBDataWriterWriteUint64Field(writer, self->_triggers, 100);
        }
    }
    /* reportFrequency */
    {
        if (self->_has.reportFrequency)
        {
            PBDataWriterWriteUint64Field(writer, self->_reportFrequency, 101);
        }
    }
    /* reportFrequencyBase */
    {
        if (self->_has.reportFrequencyBase)
        {
            PBDataWriterWriteUint64Field(writer, self->_reportFrequencyBase, 102);
        }
    }
    /* networkEvent */
    {
        if (self->_networkEvent != nil)
        {
            PBDataWriterWriteSubmessage(writer, self->_networkEvent, 200);
        }
    }
    /* genericEvent */
    {
        if (self->_genericEvent != nil)
        {
            PBDataWriterWriteSubmessage(writer, self->_genericEvent, 201);
        }
    }
}

- (void)copyTo:(SECC2MPMetric *)other
{
    if (self->_has.metricType)
    {
        other->_metricType = _metricType;
        other->_has.metricType = YES;
    }
    if (_deviceInfo)
    {
        other.deviceInfo = _deviceInfo;
    }
    if (_cloudkitInfo)
    {
        other.cloudkitInfo = _cloudkitInfo;
    }
    if (_serverInfo)
    {
        other.serverInfo = _serverInfo;
    }
    if (self->_has.triggers)
    {
        other->_triggers = _triggers;
        other->_has.triggers = YES;
    }
    if (self->_has.reportFrequency)
    {
        other->_reportFrequency = _reportFrequency;
        other->_has.reportFrequency = YES;
    }
    if (self->_has.reportFrequencyBase)
    {
        other->_reportFrequencyBase = _reportFrequencyBase;
        other->_has.reportFrequencyBase = YES;
    }
    if (_networkEvent)
    {
        other.networkEvent = _networkEvent;
    }
    if (_genericEvent)
    {
        other.genericEvent = _genericEvent;
    }
}

- (id)copyWithZone:(NSZone *)zone
{
    SECC2MPMetric *copy = [[[self class] allocWithZone:zone] init];
    if (self->_has.metricType)
    {
        copy->_metricType = _metricType;
        copy->_has.metricType = YES;
    }
    copy->_deviceInfo = [_deviceInfo copyWithZone:zone];
    copy->_cloudkitInfo = [_cloudkitInfo copyWithZone:zone];
    copy->_serverInfo = [_serverInfo copyWithZone:zone];
    if (self->_has.triggers)
    {
        copy->_triggers = _triggers;
        copy->_has.triggers = YES;
    }
    if (self->_has.reportFrequency)
    {
        copy->_reportFrequency = _reportFrequency;
        copy->_has.reportFrequency = YES;
    }
    if (self->_has.reportFrequencyBase)
    {
        copy->_reportFrequencyBase = _reportFrequencyBase;
        copy->_has.reportFrequencyBase = YES;
    }
    copy->_networkEvent = [_networkEvent copyWithZone:zone];
    copy->_genericEvent = [_genericEvent copyWithZone:zone];
    return copy;
}

- (BOOL)isEqual:(id)object
{
    SECC2MPMetric *other = (SECC2MPMetric *)object;
    return [other isMemberOfClass:[self class]]
    &&
    ((self->_has.metricType && other->_has.metricType && self->_metricType == other->_metricType) || (!self->_has.metricType && !other->_has.metricType))
    &&
    ((!self->_deviceInfo && !other->_deviceInfo) || [self->_deviceInfo isEqual:other->_deviceInfo])
    &&
    ((!self->_cloudkitInfo && !other->_cloudkitInfo) || [self->_cloudkitInfo isEqual:other->_cloudkitInfo])
    &&
    ((!self->_serverInfo && !other->_serverInfo) || [self->_serverInfo isEqual:other->_serverInfo])
    &&
    ((self->_has.triggers && other->_has.triggers && self->_triggers == other->_triggers) || (!self->_has.triggers && !other->_has.triggers))
    &&
    ((self->_has.reportFrequency && other->_has.reportFrequency && self->_reportFrequency == other->_reportFrequency) || (!self->_has.reportFrequency && !other->_has.reportFrequency))
    &&
    ((self->_has.reportFrequencyBase && other->_has.reportFrequencyBase && self->_reportFrequencyBase == other->_reportFrequencyBase) || (!self->_has.reportFrequencyBase && !other->_has.reportFrequencyBase))
    &&
    ((!self->_networkEvent && !other->_networkEvent) || [self->_networkEvent isEqual:other->_networkEvent])
    &&
    ((!self->_genericEvent && !other->_genericEvent) || [self->_genericEvent isEqual:other->_genericEvent])
    ;
}

- (NSUInteger)hash
{
    return 0
    ^
    (self->_has.metricType ? PBHashInt((NSUInteger)self->_metricType) : 0)
    ^
    [self->_deviceInfo hash]
    ^
    [self->_cloudkitInfo hash]
    ^
    [self->_serverInfo hash]
    ^
    (self->_has.triggers ? PBHashInt((NSUInteger)self->_triggers) : 0)
    ^
    (self->_has.reportFrequency ? PBHashInt((NSUInteger)self->_reportFrequency) : 0)
    ^
    (self->_has.reportFrequencyBase ? PBHashInt((NSUInteger)self->_reportFrequencyBase) : 0)
    ^
    [self->_networkEvent hash]
    ^
    [self->_genericEvent hash]
    ;
}

- (void)mergeFrom:(SECC2MPMetric *)other
{
    if (other->_has.metricType)
    {
        self->_metricType = other->_metricType;
        self->_has.metricType = YES;
    }
    if (self->_deviceInfo && other->_deviceInfo)
    {
        [self->_deviceInfo mergeFrom:other->_deviceInfo];
    }
    else if (!self->_deviceInfo && other->_deviceInfo)
    {
        [self setDeviceInfo:other->_deviceInfo];
    }
    if (self->_cloudkitInfo && other->_cloudkitInfo)
    {
        [self->_cloudkitInfo mergeFrom:other->_cloudkitInfo];
    }
    else if (!self->_cloudkitInfo && other->_cloudkitInfo)
    {
        [self setCloudkitInfo:other->_cloudkitInfo];
    }
    if (self->_serverInfo && other->_serverInfo)
    {
        [self->_serverInfo mergeFrom:other->_serverInfo];
    }
    else if (!self->_serverInfo && other->_serverInfo)
    {
        [self setServerInfo:other->_serverInfo];
    }
    if (other->_has.triggers)
    {
        self->_triggers = other->_triggers;
        self->_has.triggers = YES;
    }
    if (other->_has.reportFrequency)
    {
        self->_reportFrequency = other->_reportFrequency;
        self->_has.reportFrequency = YES;
    }
    if (other->_has.reportFrequencyBase)
    {
        self->_reportFrequencyBase = other->_reportFrequencyBase;
        self->_has.reportFrequencyBase = YES;
    }
    if (self->_networkEvent && other->_networkEvent)
    {
        [self->_networkEvent mergeFrom:other->_networkEvent];
    }
    else if (!self->_networkEvent && other->_networkEvent)
    {
        [self setNetworkEvent:other->_networkEvent];
    }
    if (self->_genericEvent && other->_genericEvent)
    {
        [self->_genericEvent mergeFrom:other->_genericEvent];
    }
    else if (!self->_genericEvent && other->_genericEvent)
    {
        [self setGenericEvent:other->_genericEvent];
    }
}

@end

