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

package org.bouncycastle.oer.its.ieee1609dot2.basetypes;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.ASN1Choice;
import org.bouncycastle.asn1.ASN1Object;

public class Duration extends ASN1Object implements ASN1Choice
{
    public static final int microseconds = 0;
    public static final int milliseconds = 1;
    public static final int seconds = 2;
    public static final int minutes = 3;
    public static final int hours = 4;
    public static final int sixtyHours = 5;
    public static final int years = 6;
    private final int choice;
    private final UINT16 duration;
    
    public Duration(final int choice, final UINT16 duration) {
        this.choice = choice;
        this.duration = duration;
    }
    
    private Duration(final ASN1TaggedObject asn1TaggedObject) {
        switch (this.choice = asn1TaggedObject.getTagNo()) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6: {
                try {
                    this.duration = UINT16.getInstance(asn1TaggedObject.getExplicitBaseObject());
                    return;
                }
                catch (final Exception cause) {
                    throw new IllegalStateException(cause.getMessage(), cause);
                }
                break;
            }
        }
        throw new IllegalArgumentException("invalid choice value " + this.choice);
    }
    
    public static Duration getInstance(final Object o) {
        if (o instanceof Duration) {
            return (Duration)o;
        }
        if (o != null) {
            return new Duration(ASN1TaggedObject.getInstance(o, 128));
        }
        return null;
    }
    
    public static Duration years(final UINT16 uint16) {
        return new Duration(6, uint16);
    }
    
    public static Duration sixtyHours(final UINT16 uint16) {
        return new Duration(5, uint16);
    }
    
    public static Duration hours(final UINT16 uint16) {
        return new Duration(4, uint16);
    }
    
    public static Duration minutes(final UINT16 uint16) {
        return new Duration(3, uint16);
    }
    
    public static Duration seconds(final UINT16 uint16) {
        return new Duration(2, uint16);
    }
    
    public static Duration milliseconds(final UINT16 uint16) {
        return new Duration(1, uint16);
    }
    
    public static Duration microseconds(final UINT16 uint16) {
        return new Duration(0, uint16);
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        return new DERTaggedObject(this.choice, this.duration);
    }
    
    public int getChoice() {
        return this.choice;
    }
    
    public UINT16 getDuration() {
        return this.duration;
    }
    
    @Override
    public String toString() {
        switch (this.choice) {
            case 0: {
                return this.duration.value + "uS";
            }
            case 1: {
                return this.duration.value + "mS";
            }
            case 2: {
                return this.duration.value + " seconds";
            }
            case 3: {
                return this.duration.value + " minute";
            }
            case 4: {
                return this.duration.value + " hours";
            }
            case 5: {
                return this.duration.value + " sixty hours";
            }
            case 6: {
                return this.duration.value + " years";
            }
            default: {
                return this.duration.value + " unknown choice";
            }
        }
    }
}
