/*
 * This file is a part of the SteamWar software.
 *
 * Copyright (C) 2020  SteamWar.de-Serverteam
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.bausystem.region.dynamic;

import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Cleanup;
import lombok.SneakyThrows;

import java.io.File;
import java.io.FileWriter;
import java.util.UUID;

@Builder
@AllArgsConstructor
public class RegionConstructorData {

    public final String regionClass;
    public final UUID uuid;
    public final int minX;
    public final int minZ;

    public RegionConstructorData(JsonObject jsonObject, UUID uuid) {
        regionClass = jsonObject.get("regionClass").getAsString();
        this.uuid = uuid;
        minX = jsonObject.get("minX").getAsInt();
        minZ = jsonObject.get("minZ").getAsInt();
    }

    @SneakyThrows
    public void write(File file) {
        @Cleanup
        JsonWriter writer = new JsonWriter(new FileWriter(file));
        writer.setIndent("  ");
        writer.beginObject();
        writer.name("regionClass").value(regionClass);
        writer.name("minX").value(minX);
        writer.name("minZ").value(minZ);
        writer.endObject();
    }
}
