// 
// 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.etsi102941.basetypes.CertificateSubjectAttributes;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Object;

public class AuthorizationValidationResponse extends ASN1Object
{
    private final ASN1OctetString requestHash;
    private final AuthorizationValidationResponseCode responseCode;
    private final CertificateSubjectAttributes confirmedSubjectAttributes;
    
    public AuthorizationValidationResponse(final ASN1OctetString requestHash, final AuthorizationValidationResponseCode responseCode, final CertificateSubjectAttributes confirmedSubjectAttributes) {
        this.requestHash = requestHash;
        this.responseCode = responseCode;
        this.confirmedSubjectAttributes = confirmedSubjectAttributes;
    }
    
    private AuthorizationValidationResponse(final ASN1Sequence asn1Sequence) {
        if (asn1Sequence.size() != 3) {
            throw new IllegalArgumentException("expected sequence size of 3");
        }
        this.requestHash = ASN1OctetString.getInstance(asn1Sequence.getObjectAt(0));
        this.responseCode = AuthorizationValidationResponseCode.getInstance(asn1Sequence.getObjectAt(1));
        this.confirmedSubjectAttributes = OEROptional.getValue(CertificateSubjectAttributes.class, asn1Sequence.getObjectAt(2));
    }
    
    public static AuthorizationValidationResponse getInstance(final Object o) {
        if (o instanceof AuthorizationValidationResponse) {
            return (AuthorizationValidationResponse)o;
        }
        if (o != null) {
            return new AuthorizationValidationResponse(ASN1Sequence.getInstance(o));
        }
        return null;
    }
    
    public ASN1OctetString getRequestHash() {
        return this.requestHash;
    }
    
    public AuthorizationValidationResponseCode getResponseCode() {
        return this.responseCode;
    }
    
    public CertificateSubjectAttributes getConfirmedSubjectAttributes() {
        return this.confirmedSubjectAttributes;
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return new DERSequence(new ASN1Encodable[] { this.requestHash, this.responseCode, OEROptional.getInstance(this.confirmedSubjectAttributes) });
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static class Builder
    {
        private ASN1OctetString requestHash;
        private AuthorizationValidationResponseCode responseCode;
        private CertificateSubjectAttributes confirmedSubjectAttributes;
        
        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 AuthorizationValidationResponseCode responseCode) {
            this.responseCode = responseCode;
            return this;
        }
        
        public Builder setConfirmedSubjectAttributes(final CertificateSubjectAttributes confirmedSubjectAttributes) {
            this.confirmedSubjectAttributes = confirmedSubjectAttributes;
            return this;
        }
        
        public AuthorizationValidationResponse createAuthorizationValidationResponse() {
            return new AuthorizationValidationResponse(this.requestHash, this.responseCode, this.confirmedSubjectAttributes);
        }
    }
}
