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

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

#import "SECC2MPGenericEventMetric.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 SECC2MPGenericEvent

@synthesize type = _type;
- (SECC2MPGenericEvent_Type)type
{
    return _has.type ? _type : SECC2MPGenericEvent_Type_none;
}
- (void)setType:(SECC2MPGenericEvent_Type)v
{
    _has.type = YES;
    _type = v;
}
- (void)setHasType:(BOOL)f
{
    _has.type = f;
}
- (BOOL)hasType
{
    return _has.type;
}
- (NSString *)typeAsString:(SECC2MPGenericEvent_Type)value
{
    return SECC2MPGenericEvent_TypeAsString(value);
}
- (SECC2MPGenericEvent_Type)StringAsType:(NSString *)str
{
    return StringAsSECC2MPGenericEvent_Type(str);
}
- (BOOL)hasName
{
    return _name != nil;
}
@synthesize name = _name;
@synthesize timestampStart = _timestampStart;
- (void)setTimestampStart:(uint64_t)v
{
    _has.timestampStart = YES;
    _timestampStart = v;
}
- (void)setHasTimestampStart:(BOOL)f
{
    _has.timestampStart = f;
}
- (BOOL)hasTimestampStart
{
    return _has.timestampStart;
}
@synthesize timestampEnd = _timestampEnd;
- (void)setTimestampEnd:(uint64_t)v
{
    _has.timestampEnd = YES;
    _timestampEnd = v;
}
- (void)setHasTimestampEnd:(BOOL)f
{
    _has.timestampEnd = f;
}
- (BOOL)hasTimestampEnd
{
    return _has.timestampEnd;
}
@synthesize metrics = _metrics;
- (void)clearMetrics
{
    [_metrics removeAllObjects];
}
- (void)addMetric:(SECC2MPGenericEventMetric *)i
{
    if (!_metrics)
    {
        _metrics = [[NSMutableArray alloc] init];
    }
    [_metrics addObject:i];
}
- (NSUInteger)metricsCount
{
    return [_metrics count];
}
- (SECC2MPGenericEventMetric *)metricAtIndex:(NSUInteger)idx
{
    return [_metrics objectAtIndex:idx];
}
+ (Class)metricType
{
    return [SECC2MPGenericEventMetric class];
}

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

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if (self->_has.type)
    {
        [dict setObject:SECC2MPGenericEvent_TypeAsString(self->_type) forKey:@"type"];
    }
    if (self->_name)
    {
        [dict setObject:self->_name forKey:@"name"];
    }
    if (self->_has.timestampStart)
    {
        [dict setObject:[NSNumber numberWithUnsignedLongLong:self->_timestampStart] forKey:@"timestamp_start"];
    }
    if (self->_has.timestampEnd)
    {
        [dict setObject:[NSNumber numberWithUnsignedLongLong:self->_timestampEnd] forKey:@"timestamp_end"];
    }
    if ([self->_metrics count])
    {
        NSMutableArray *metricsDictReprs = [[NSMutableArray alloc] initWithCapacity:[self->_metrics count]];
        for (SECC2MPGenericEventMetric *i_metric in self->_metrics)
        {
            [metricsDictReprs addObject:[i_metric dictionaryRepresentation]];
        }
        [dict setObject:metricsDictReprs forKey:@"metric"];
    }
    return dict;
}

BOOL SECC2MPGenericEventReadFrom(__unsafe_unretained SECC2MPGenericEvent *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 /* type */:
            {
                self->_has.type = YES;
                self->_type = PBReaderReadInt32(reader);
            }
            break;
            case 101 /* name */:
            {
                NSString *new_name = PBReaderReadString(reader);
                self->_name = new_name;
            }
            break;
            case 201 /* timestampStart */:
            {
                self->_has.timestampStart = YES;
                self->_timestampStart = PBReaderReadUint64(reader);
            }
            break;
            case 202 /* timestampEnd */:
            {
                self->_has.timestampEnd = YES;
                self->_timestampEnd = PBReaderReadUint64(reader);
            }
            break;
            case 301 /* metrics */:
            {
                SECC2MPGenericEventMetric *new_metric = [[SECC2MPGenericEventMetric alloc] init];
                [self addMetric:new_metric];
                PBDataReaderMark mark_metric;
                BOOL markError = !PBReaderPlaceMark(reader, &mark_metric);
                if (markError)
                {
                    return NO;
                }
                BOOL inError = !SECC2MPGenericEventMetricReadFrom(new_metric, reader);
                if (inError)
                {
                    return NO;
                }
                PBReaderRecallMark(reader, &mark_metric);
            }
            break;
            default:
                if (!PBReaderSkipValueWithTag(reader, tag, aType))
                    return NO;
                break;
        }
    }
    return !PBReaderHasError(reader);
}

- (BOOL)readFrom:(PBDataReader *)reader
{
    return SECC2MPGenericEventReadFrom(self, reader);
}
- (void)writeTo:(PBDataWriter *)writer
{
    /* type */
    {
        if (self->_has.type)
        {
            PBDataWriterWriteInt32Field(writer, self->_type, 1);
        }
    }
    /* name */
    {
        if (self->_name)
        {
            PBDataWriterWriteStringField(writer, self->_name, 101);
        }
    }
    /* timestampStart */
    {
        if (self->_has.timestampStart)
        {
            PBDataWriterWriteUint64Field(writer, self->_timestampStart, 201);
        }
    }
    /* timestampEnd */
    {
        if (self->_has.timestampEnd)
        {
            PBDataWriterWriteUint64Field(writer, self->_timestampEnd, 202);
        }
    }
    /* metrics */
    {
        for (SECC2MPGenericEventMetric *i_metric in self->_metrics)
        {
            PBDataWriterWriteSubmessage(writer, i_metric, 301);
        }
    }
}

- (void)copyTo:(SECC2MPGenericEvent *)other
{
    if (self->_has.type)
    {
        other->_type = _type;
        other->_has.type = YES;
    }
    if (_name)
    {
        other.name = _name;
    }
    if (self->_has.timestampStart)
    {
        other->_timestampStart = _timestampStart;
        other->_has.timestampStart = YES;
    }
    if (self->_has.timestampEnd)
    {
        other->_timestampEnd = _timestampEnd;
        other->_has.timestampEnd = YES;
    }
    if ([self metricsCount])
    {
        [other clearMetrics];
        NSUInteger metricsCnt = [self metricsCount];
        for (NSUInteger i = 0; i < metricsCnt; i++)
        {
            [other addMetric:[self metricAtIndex:i]];
        }
    }
}

- (id)copyWithZone:(NSZone *)zone
{
    SECC2MPGenericEvent *copy = [[[self class] allocWithZone:zone] init];
    if (self->_has.type)
    {
        copy->_type = _type;
        copy->_has.type = YES;
    }
    copy->_name = [_name copyWithZone:zone];
    if (self->_has.timestampStart)
    {
        copy->_timestampStart = _timestampStart;
        copy->_has.timestampStart = YES;
    }
    if (self->_has.timestampEnd)
    {
        copy->_timestampEnd = _timestampEnd;
        copy->_has.timestampEnd = YES;
    }
    for (SECC2MPGenericEventMetric *v in _metrics)
    {
        SECC2MPGenericEventMetric *vCopy = [v copyWithZone:zone];
        [copy addMetric:vCopy];
    }
    return copy;
}

- (BOOL)isEqual:(id)object
{
    SECC2MPGenericEvent *other = (SECC2MPGenericEvent *)object;
    return [other isMemberOfClass:[self class]]
    &&
    ((self->_has.type && other->_has.type && self->_type == other->_type) || (!self->_has.type && !other->_has.type))
    &&
    ((!self->_name && !other->_name) || [self->_name isEqual:other->_name])
    &&
    ((self->_has.timestampStart && other->_has.timestampStart && self->_timestampStart == other->_timestampStart) || (!self->_has.timestampStart && !other->_has.timestampStart))
    &&
    ((self->_has.timestampEnd && other->_has.timestampEnd && self->_timestampEnd == other->_timestampEnd) || (!self->_has.timestampEnd && !other->_has.timestampEnd))
    &&
    ((!self->_metrics && !other->_metrics) || [self->_metrics isEqual:other->_metrics])
    ;
}

- (NSUInteger)hash
{
    return 0
    ^
    (self->_has.type ? PBHashInt((NSUInteger)self->_type) : 0)
    ^
    [self->_name hash]
    ^
    (self->_has.timestampStart ? PBHashInt((NSUInteger)self->_timestampStart) : 0)
    ^
    (self->_has.timestampEnd ? PBHashInt((NSUInteger)self->_timestampEnd) : 0)
    ^
    [self->_metrics hash]
    ;
}

- (void)mergeFrom:(SECC2MPGenericEvent *)other
{
    if (other->_has.type)
    {
        self->_type = other->_type;
        self->_has.type = YES;
    }
    if (other->_name)
    {
        [self setName:other->_name];
    }
    if (other->_has.timestampStart)
    {
        self->_timestampStart = other->_timestampStart;
        self->_has.timestampStart = YES;
    }
    if (other->_has.timestampEnd)
    {
        self->_timestampEnd = other->_timestampEnd;
        self->_has.timestampEnd = YES;
    }
    for (SECC2MPGenericEventMetric *iter_metrics in other->_metrics)
    {
        [self addMetric:iter_metrics];
    }
}

@end

