/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_2487
 *  net.minecraft.class_2499
 *  net.minecraft.class_2520
 */
package meteordevelopment.meteorclient.systems.publicconfigs;

import java.util.ArrayList;
import java.util.List;
import meteordevelopment.meteorclient.utils.misc.ISerializable;
import net.minecraft.class_2487;
import net.minecraft.class_2499;
import net.minecraft.class_2520;

public class PublicConfig
implements ISerializable<PublicConfig> {
    public String name;
    public String content;
    public String author;
    public boolean pinned;
    public List<Comment> comments = new ArrayList<Comment>();

    public PublicConfig() {
    }

    public PublicConfig(String name, String content, String author) {
        this.name = name;
        this.content = content;
        this.author = author;
        this.pinned = false;
    }

    @Override
    public class_2487 toTag() {
        class_2487 tag = new class_2487();
        tag.method_10582("name", this.name);
        tag.method_10582("content", this.content);
        tag.method_10582("author", this.author);
        tag.method_10556("pinned", this.pinned);
        class_2499 list = new class_2499();
        for (Comment comment : this.comments) {
            list.add((Object)comment.toTag());
        }
        tag.method_10566("comments", (class_2520)list);
        return tag;
    }

    @Override
    public PublicConfig fromTag(class_2487 tag) {
        this.name = tag.method_68564("name", "");
        this.content = tag.method_68564("content", "");
        this.author = tag.method_68564("author", "");
        this.pinned = tag.method_68566("pinned", false);
        this.comments.clear();
        if (tag.method_10545("comments")) {
            class_2499 list = tag.method_68569("comments");
            for (int i = 0; i < list.size(); ++i) {
                this.comments.add(new Comment().fromTag((class_2487)list.get(i)));
            }
        }
        return this;
    }

    public static class Comment
    implements ISerializable<Comment> {
        public String author;
        public String text;

        public Comment() {
        }

        public Comment(String author, String text) {
            this.author = author;
            this.text = text;
        }

        @Override
        public class_2487 toTag() {
            class_2487 tag = new class_2487();
            tag.method_10582("author", this.author);
            tag.method_10582("text", this.text);
            return tag;
        }

        @Override
        public Comment fromTag(class_2487 tag) {
            this.author = tag.method_68564("author", "");
            this.text = tag.method_68564("text", "");
            return this;
        }
    }
}

