package be.iminds.ilabt.jfed.experimenter_gui.tutorials;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

import javax.annotation.Nullable;
import java.net.URL;
import java.util.List;

/**
 * User: twalcari
 * Date: 3/10/2016
 * Time: 15:29
 */
@JacksonXmlRootElement(localName = "f4ftut")
public class Tutorial {

    private String id;
    private String title;
    private URL image;
    private String description;
    private String text;
    private List<TutFileWithContents> files;

    @JsonProperty
    @JacksonXmlProperty(isAttribute = true)
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @JsonProperty
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @JsonProperty
    public URL getImage() {
        return image;
    }

    public void setImage(URL image) {
        this.image = image;
    }

    @JsonProperty
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @JsonProperty
    @JacksonXmlCData
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Nullable
    public List<TutFileWithContents> getFiles() {
        return files;
    }

    public void setFiles(List<TutFileWithContents> files) {
        this.files = files;
    }

  /*  @JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, property = "class", include = JsonTypeInfo.As.PROPERTY)
    @JsonSubTypes({
            @JsonSubTypes.Type(name = "file", value = TutFileWithContents.class),
            @JsonSubTypes.Type(name = "file-ref", value = TutFileRef.class)})          */
    public static class TutFile {
        public String name;
        public String type;


        public TutFile() {
        }

        public TutFile(String name, String type) {
            this.name = name;
            this.type = type;
        }

        @JsonProperty
        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        @JsonProperty
        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    @JacksonXmlRootElement(localName = "file")
    public static class TutFileWithContents extends TutFile {

        public String content;


        @JsonProperty
        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }
          /*
    @JacksonXmlRootElement(localName = "file-ref")
    public static class TutFileRef extends TutFile {

        public URL url;

        public URL getUrl() {
            return url;
        }

        public void setUrl(URL url) {
            this.url = url;
        }
    }   */

}
