/*
 * Copyright 2016 The original authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package io.sundr.codegen.converters;

import io.sundr.codegen.functions.ElementTo;
import io.sundr.codegen.model.TypeDefBuilder;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementVisitor;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;

public class TypeDefElementVisitor implements ElementVisitor<TypeDefBuilder, Void> {

    private final TypeDefBuilder builder = new TypeDefBuilder();

    public TypeDefBuilder visit(Element e, Void aVoid) {
        return builder.withName(e.getSimpleName().toString());
    }

    public TypeDefBuilder visit(Element e) {
        String name = e.getSimpleName().toString();
        builder.withName(name);
        if (e.getEnclosingElement() instanceof PackageElement) {
            String packageName = e.getEnclosingElement().toString();
            builder.withPackageName(packageName);
        }
        return builder;
    }

    public TypeDefBuilder visitPackage(PackageElement e, Void aVoid) {
        return builder.withPackageName(e.getQualifiedName().toString());
    }

    public TypeDefBuilder visitType(TypeElement e, Void aVoid) {
        return builder.withName(e.getSimpleName().toString());
    }

    public TypeDefBuilder visitVariable(VariableElement e, Void aVoid) {
        return builder.addToProperties(ElementTo.PROPERTY.apply(e));
    }

    public TypeDefBuilder visitExecutable(ExecutableElement e, Void aVoid) {
        return builder.addToMethods(ElementTo.METHOD.apply(e));
    }

    public TypeDefBuilder visitTypeParameter(TypeParameterElement e, Void aVoid) {
        return builder.addToParameters(ElementTo.TYPEPARAMDEF.apply(e));
    }

    public TypeDefBuilder visitUnknown(Element e, Void aVoid) {
        return builder;
    }
}

@@ -709,16 +709,52 @@
 mentTo;%0A
+import io.sundr.codegen.model.Kind;%0A
 import i
@@ -825,32 +825,77 @@
 lement.Element;%0A
+import javax.lang.model.element.ElementKind;%0A
 import javax.lan
@@ -1578,24 +1578,399 @@
 Name(name);%0A
+        if (e.getKind() == ElementKind.INTERFACE) %7B%0A            builder.withKind(Kind.INTERFACE);%0A        %7D else if (e.getKind() == ElementKind.ENUM) %7B%0A            builder.withKind(Kind.ENUM);%0A        %7Delse if (e.getKind() == ElementKind.ANNOTATION_TYPE) %7B%0A            builder.withKind(Kind.ANNOTATION);%0A        %7D else  %7B%0A            builder.withKind(Kind.CLASS);%0A        %7D%0A%0A
         if (

Improve Kind translation on TypeDefElementVisitor.