/*
 * Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in all
 *  copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *  SOFTWARE.
 */

package me.lucko.luckperms.common.storage.backing.utils;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import me.lucko.luckperms.api.Node;

@Getter
@ToString
@AllArgsConstructor(staticName = "of")
public class NodeDataHolder {
    public static NodeDataHolder fromNode(Node node) {
        // TODO
        return null;
    }

    private final String permission;
    private final boolean value;
    private final String server;
    private final String world;
    private final long expiry;
    private final String contexts;

    public Node toNode() {
        // TODO
        return null;
    }

}

@@ -1200,16 +1200,101 @@
 utils;%0A%0A
+import com.google.gson.JsonParseException;%0Aimport com.google.gson.reflect.TypeToken;%0A
 import l
@@ -1364,16 +1364,45 @@
 oString;
+%0Aimport com.google.gson.Gson;
 %0A%0Aimport
@@ -1430,16 +1430,147 @@
 pi.Node;
+%0Aimport me.lucko.luckperms.common.core.NodeBuilder;%0A%0Aimport java.lang.reflect.Type;%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0A@Gette
@@ -1717,308 +1717,1053 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    private final String permission;%0A    private final boolean value;%0A    private final String server;%0A    private final String world;%0A    private final long expiry;%0A    private final String contexts;%0A%0A    public Node toNode() %7B%0A        // TODO%0A        return null
+long expiry = node.isTemporary() ? node.getExpiryUnixTime() : 0L;%0A        return NodeDataHolder.of(node.getPermission(), node.getValue(),%0A                node.getServer().orElse(null), node.getWorld().orElse(null),%0A                expiry, new Gson().toJson(node.getContexts().toMap()));%0A    %7D%0A%0A    private final String permission;%0A    private final boolean value;%0A    private final String server;%0A    private final String world;%0A    private final long expiry;%0A    private final String contexts;%0A%0A    public Node toNode() %7B%0A        Type type = new TypeToken%3CMap%3CString, String%3E%3E()%7B%7D.getType();%0A        Map%3CString, String%3E parsedContexts = new Gson().fromJson(contexts, type);%0A        if (parsedContexts == null) %7B%0A            parsedContexts = new HashMap%3C%3E();%0A        %7D%0A%0A        NodeBuilder builder = new NodeBuilder(permission);%0A        builder.setValue(value);%0A        builder.setServer(server);%0A        builder.setWorld(world);%0A        builder.setExpiry(expiry);%0A        builder.withExtraContext(parsedContexts);%0A        return builder.build()
 ;%0A  

Implement NodeDataHolder