package $javaPackage;

/**
 * Provides extra data of {@link android.content.Intent Intents} from {@link ${targetActivity}}.
 */
@javax.annotation.Generated("org.cryptomator.generator.IntentProcessor")
class $className implements $intentInterface {

#foreach( $parameter in $parameters )
    private $parameter.type $parameter.name;
#end

    public $className(${targetActivity} activity) {
        android.content.Intent intent = activity.getIntent();
#foreach( $parameter in $parameters )
        this.${parameter.name} = readExtra(intent, "$parameter.name", $parameter.required, ${parameter.type}.class);
#end
    }

    private static <T> T readExtra(android.content.Intent intent, String name, boolean required, Class<T> type) {
        android.os.Bundle extras = intent.getExtras();
        Object value = null;
        if (extras != null) {
            value = extras.get(name);
        }
        if (value == null) {
            if (required) {
                throw new IllegalStateException("Missing value for required extra " + name);
            }
            return null;
        } else if (!type.isInstance(value)) {
            throw new IllegalStateException("Invalid type of extra " + name + ". Expected " + type.getName() + " but got " + value.getClass().getName());
        }
        return type.cast(value);
    }

#foreach( $parameter in $parameters )
    /**
     * @return the value of the extra $parameter.name
     */
    public $parameter.type ${parameter.name}() {
        return this.$parameter.name;
    }

#end

}
