package org.gnode.nix;

import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.annotation.*;
import org.gnode.nix.internal.Utils;

import java.util.Date;

@Platform(value = "linux",
        include = {"<nix/Block.hpp>"},
        link = {"nix"})
@Namespace("nix")
public class Block extends Pointer {

    static {
        Loader.load();
    }

    /**
     * Constructor that creates an uninitialized Block.
     * <p/>
     * Calling any method on an uninitialized block will throw a {@link java.lang.RuntimeException}.
     */
    public Block() {
        allocate();
    }

    private native void allocate();

    //--------------------------------------------------
    // Base class methods
    //--------------------------------------------------

    private native
    @Cast("bool")
    boolean isNone();

    /**
     * Checks if block is initialized
     *
     * @return true if initialized, False otherwise
     */
    public boolean isInitialized() {
        return !isNone();
    }

    /**
     * Get id of the block
     *
     * @return id string
     */
    public native
    @Name("id")
    @StdString
    String getId();

    private native
    @Cast("time_t")
    long createdAt();

    /**
     * Get the creation date of the block.
     *
     * @return The creation date of the block.
     */
    public Date getCreatedAt() {
        return Utils.convertSecondsToDate(createdAt());
    }

    private native
    @Cast("time_t")
    long updatedAt();

    /**
     * Get the date of the last update.
     *
     * @return The date of the last update.
     */
    public Date getUpdatedAt() {
        return Utils.convertSecondsToDate(updatedAt());
    }

    /**
     * Sets the time of the last update to the current time if the field is not set.
     */
    public native void setUpdatedAt();

    /**
     * Sets the time of the last update to the current time.
     */
    public native void forceUpdatedAt();

    /**
     * Sets the creation time to the current time if the field is not set.
     */
    public native void setCreatedAt();

    private native void forceCreatedAt(@Cast("time_t") long time);

    /**
     * Sets the creation date to the provided value even if the attribute is set.
     *
     * @param date The creation date to set.
     */
    public void forceCreatedAt(Date date) {
        forceCreatedAt(Utils.convertDateToSeconds(date));
    }

}
@@ -132,16 +132,98 @@
 tion.*;%0A
+import org.gnode.nix.internal.None;%0Aimport org.gnode.nix.internal.OptionalString;%0A
 import o
@@ -2518,9 +2518,1342 @@
 %0A    %7D%0A%0A
+    /**%0A     * Setter for the type of the block%0A     *%0A     * @param type The type of the block%0A     */%0A    public native%0A    @Name(%22type%22)%0A    void setType(@StdString String type);%0A%0A    /**%0A     * Getter for the type of the block%0A     *%0A     * @return The type of the block%0A     */%0A    public native%0A    @Name(%22type%22)%0A    @StdString%0A    String getType();%0A%0A    /**%0A     * Getter for the name of the block.%0A     *%0A     * @return The name of the block.%0A     */%0A    public native%0A    @Name(%22name%22)%0A    @StdString%0A    String getName();%0A%0A    /**%0A     * Setter for the definition of the block.%0A     *%0A     * @param definition The definition of the block.%0A     */%0A    public native%0A    @Name(%22definition%22)%0A    void setDefinition(@StdString String definition);%0A%0A    private native%0A    @ByVal%0A    OptionalString definition();%0A%0A    /**%0A     * Getter for the definition of the block.%0A     *%0A     * @return The definition of the block.%0A     */%0A    public String getDefinition() %7B%0A        OptionalString defintion = definition();%0A        if (defintion.isPresent()) %7B%0A            return defintion.getString();%0A        %7D%0A        return null;%0A    %7D%0A%0A    private native void definition(@Const @ByVal None t);%0A%0A    /**%0A     * Deletes for the definition of the block.%0A     */%0A    public void removeDefinition() %7B%0A        definition(new None());%0A    %7D%0A%0A
 %7D

add named entity base methods for block