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

package org.bouncycastle.oer.its.etsi102941;

import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.asn1.DERSequence;
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.etsi103097.EtsiTs103097Certificate;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Object;

public class InnerEcResponse extends ASN1Object
{
    private final ASN1OctetString requestHash;
    private final EnrolmentResponseCode responseCode;
    private final EtsiTs103097Certificate certificate;
    
    public InnerEcResponse(final ASN1OctetString requestHash, final EnrolmentResponseCode responseCode, final EtsiTs103097Certificate certificate) {
        this.requestHash = requestHash;
        this.responseCode = responseCode;
        this.certificate = certificate;
    }
    
    private InnerEcResponse(final ASN1Sequence asn1Sequence) {
        if (asn1Sequence.size() != 3) {
            throw new IllegalArgumentException("expected sequence size of 3");
        }
        this.requestHash = ASN1OctetString.getInstance(asn1Sequence.getObjectAt(0));
        this.responseCode = EnrolmentResponseCode.getInstance(asn1Sequence.getObjectAt(1));
        this.certificate = OEROptional.getValue(EtsiTs103097Certificate.class, asn1Sequence.getObjectAt(2));
    }
    
    public static InnerEcResponse getInstance(final Object o) {
        if (o instanceof InnerEcResponse) {
            return (InnerEcResponse)o;
        }
        if (o != null) {
            return new InnerEcResponse(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    public ASN1OctetString getRequestHash() {
        return this.requestHash;
    }
    
    public EnrolmentResponseCode getResponseCode() {
        return this.responseCode;
    }
    
    public EtsiTs103097Certificate getCertificate() {
        return this.certificate;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return new DERSequence(new ASN1Encodable[] { this.requestHash, this.responseCode, OEROptional.getInstance(this.certificate) });
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder
    {
        private ASN1OctetString requestHash;
        private EnrolmentResponseCode responseCode;
        private EtsiTs103097Certificate certificate;
        
        public Builder setRequestHash(final ASN1OctetString requestHash) {
            this.requestHash = requestHash;
            return this;
        }
        
        public Builder setRequestHash(final byte[] array) {
            this.requestHash = new DEROctetString(Arrays.clone(array));
            return this;
        }
        
        public Builder setResponseCode(final EnrolmentResponseCode responseCode) {
            this.responseCode = responseCode;
            return this;
        }
        
        public Builder setCertificate(final EtsiTs103097Certificate certificate) {
            this.certificate = certificate;
            return this;
        }
        
        public InnerEcResponse createInnerEcResponse() {
            return new InnerEcResponse(this.requestHash, this.responseCode, this.certificate);
        }
    }
}
