// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.oer.its.ieee1609dot2dot1;

import org.bouncycastle.oer.its.ItsUtils;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.oer.OEROptional;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.oer.its.ieee1609dot2.ToBeSignedCertificate;
import org.bouncycastle.oer.its.ieee1609dot2.CertificateType;
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.Time32;
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.UINT8;
import org.bouncycastle.asn1.ASN1Object;

public class EeRaCertRequest extends ASN1Object
{
    private final UINT8 version;
    private final Time32 generationTime;
    private final CertificateType type;
    private final ToBeSignedCertificate tbsCert;
    private final AdditionalParams additionalParams;
    
    public EeRaCertRequest(final UINT8 version, final Time32 generationTime, final CertificateType type, final ToBeSignedCertificate tbsCert, final AdditionalParams additionalParams) {
        this.version = version;
        this.generationTime = generationTime;
        this.type = type;
        this.tbsCert = tbsCert;
        this.additionalParams = additionalParams;
    }
    
    private EeRaCertRequest(final ASN1Sequence asn1Sequence) {
        if (asn1Sequence.size() != 5) {
            throw new IllegalArgumentException("expected sequence size of 5");
        }
        this.version = UINT8.getInstance(asn1Sequence.getObjectAt(0));
        this.generationTime = Time32.getInstance(asn1Sequence.getObjectAt(1));
        this.type = CertificateType.getInstance(asn1Sequence.getObjectAt(2));
        this.tbsCert = ToBeSignedCertificate.getInstance(asn1Sequence.getObjectAt(3));
        this.additionalParams = OEROptional.getInstance(asn1Sequence.getObjectAt(4)).getObject(AdditionalParams.class);
    }
    
    public static EeRaCertRequest getInstance(final Object o) {
        if (o instanceof EeRaCertRequest) {
            return (EeRaCertRequest)o;
        }
        if (o != null) {
            return new EeRaCertRequest(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public UINT8 getVersion() {
        return this.version;
    }
    
    public Time32 getGenerationTime() {
        return this.generationTime;
    }
    
    public CertificateType getType() {
        return this.type;
    }
    
    public ToBeSignedCertificate getTbsCert() {
        return this.tbsCert;
    }
    
    public AdditionalParams getAdditionalParams() {
        return this.additionalParams;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return ItsUtils.toSequence(this.version, this.generationTime, this.type, this.tbsCert, OEROptional.getInstance(this.additionalParams));
    }
    
    public static class Builder
    {
        private UINT8 version;
        private Time32 generationTime;
        private CertificateType type;
        private ToBeSignedCertificate tbsCert;
        private AdditionalParams additionalParams;
        
        public Builder setVersion(final UINT8 version) {
            this.version = version;
            return this;
        }
        
        public Builder setGenerationTime(final Time32 generationTime) {
            this.generationTime = generationTime;
            return this;
        }
        
        public Builder setType(final CertificateType type) {
            this.type = type;
            return this;
        }
        
        public Builder setTbsCert(final ToBeSignedCertificate tbsCert) {
            this.tbsCert = tbsCert;
            return this;
        }
        
        public Builder setAdditionalParams(final AdditionalParams additionalParams) {
            this.additionalParams = additionalParams;
            return this;
        }
        
        public EeRaCertRequest createEeRaCertRequest() {
            return new EeRaCertRequest(this.version, this.generationTime, this.type, this.tbsCert, this.additionalParams);
        }
    }
}
