/*
 * This file is part of Total Economy, licensed under the MIT License (MIT).
 *
 * Copyright (c) Eric Grandt <https://www.ericgrandt.com>
 * Copyright (c) contributors
 *
 * 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 com.erigitic.jobs;

import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class TEJob {
    private List<String> sets;

    private BigDecimal salary;

    private JobBasedRequirement requirement;

    private TEJob() {
        sets = new ArrayList<>();
    }

    public static TEJob of(ConfigurationNode node) {
        TEJob job = new TEJob();

        if (job.load(node))
            return job;

        return null;
    }

    public List<String> getSets() {
        return sets;
    }

    public boolean salaryEnabled() {
        return !salary.equals(BigDecimal.ZERO);
    }

    public BigDecimal getSalary() {
        return salary;
    }

    /**
     * Read values from a {@link ConfigurationNode}
     */
    protected boolean load(ConfigurationNode node) {
        salary = new BigDecimal(node.getNode("salary").getString("0"));

        try {
            sets = node.getNode("sets").getList(TypeToken.of(String.class), new ArrayList<String>());

            if (!node.getNode("require").isVirtual()) {
                requirement = JobBasedRequirement.of(node.getNode("require"));
            }

            return true;
        } catch (ObjectMappingException e) {
            e.printStackTrace();
        }

        return false;
    }

    public Optional<JobBasedRequirement> getRequirement() {
        return Optional.ofNullable(requirement);
    }
}

@@ -1585,27 +1585,20 @@
 ate 
-List%3C
 String
-%3E sets;%0A
+ name;
 %0A   
@@ -1625,16 +1625,66 @@
 salary;%0A
+    private List%3CString%3E sets = new ArrayList%3C%3E();
 %0A    pri
@@ -1738,57 +1738,32 @@
 ate 
-TEJob() %7B%0A        sets = new ArrayList%3C%3E();%0A    %7D
+boolean isValid = false;
 %0A%0A  
@@ -1775,23 +1775,13 @@
 lic 
-static 
 TEJob
- of
 (Con
@@ -1815,107 +1815,367 @@
     
-TEJob job = new TEJob();%0A%0A        if (job.load(node))%0A            return job;%0A%0A        return null;
+name = node.getKey().toString();%0A        salary = new BigDecimal(node.getNode(%22salary%22).getString());%0A%0A        try %7B%0A            sets = node.getNode(%22sets%22).getList(TypeToken.of(String.class), new ArrayList%3C%3E());%0A%0A            isValid = true;%0A        %7D catch (ObjectMappingException e) %7B%0A            isValid = false;%0A%0A            e.printStackTrace();%0A        %7D
 %0A   
@@ -2326,32 +2326,78 @@
 l.ZERO);%0A    %7D%0A%0A
+    public String getName() %7B return name; %7D%0A%0A
     public BigDe
@@ -2450,612 +2450,8 @@
  %7D%0A%0A
-    /**%0A     * Read values from a %7B@link ConfigurationNode%7D%0A     */%0A    protected boolean load(ConfigurationNode node) %7B%0A        salary = new BigDecimal(node.getNode(%22salary%22).getString(%220%22));%0A%0A        try %7B%0A            sets = node.getNode(%22sets%22).getList(TypeToken.of(String.class), new ArrayList%3CString%3E());%0A%0A            if (!node.getNode(%22require%22).isVirtual()) %7B%0A                requirement = JobBasedRequirement.of(node.getNode(%22require%22));%0A            %7D%0A%0A            return true;%0A        %7D catch (ObjectMappingException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        return false;%0A    %7D%0A%0A
     
@@ -2560,11 +2560,73 @@
 );%0A    %7D
+%0A%0A    public boolean isValid() %7B%0A        return isValid;%0A    %7D
 %0A%7D%0A

Update TEJob class