/*
 * 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.spawn;

import de.steamwar.bausystem.region.GameModeConfig;
import de.steamwar.bausystem.region.RegionHistory;
import de.steamwar.bausystem.region.RegionType;
import de.steamwar.bausystem.region.dynamic.*;
import lombok.NonNull;
import org.bukkit.Bukkit;

import java.io.File;

public class SpawnRegion extends DynamicRegion {

    private static final File SECTIONS_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections");
    private static final File RESET_FILE = new File(SECTIONS_DIR, "spawn/SpawnMiddle.schem");

    private DefaultFlagStorage flagStorage = new NonNormalFlagStorage();
    private final Area area;

    public SpawnRegion(int minX, int minZ) {
        super(minX, minZ);
        RegionDataRepository.loadFlagStorage(this, flagStorage);
        area = new SpawnAreaTile(minX, minZ, VariantSelector.File(RESET_FILE), this);
    }

    public SpawnRegion(RegionConstructorData regionConstructorData) {
        super(regionConstructorData);
        RegionDataRepository.loadFlagStorage(this, flagStorage);
        area = new SpawnAreaTile(minX, minZ, VariantSelector.File(RESET_FILE), this);
    }

    @Override
    public void update(DynamicRegion updateFrom) {
        SpawnResetter.reset(null);
    }

    @Override
    public void setFlags(DefaultFlagStorage flags) {
    }

    @Override
    public @NonNull RegionType getType() {
        return RegionType.SPAWN;
    }

    @Override
    public @NonNull DefaultFlagStorage getFlags() {
        return flagStorage;
    }

    @Override
    public @NonNull Area getArea() {
        return area;
    }

    @Override
    public @NonNull Area getBuildArea() {
        return Area.EMPTY;
    }

    @Override
    public @NonNull Area getTestblockArea() {
        return Area.EMPTY;
    }

    @Override
    public @NonNull GameModeConfig getGameModeConfig() {
        return GameModeConfig.EMPTY;
    }

    @Override
    public @NonNull RegionHistory getHistory() {
        return RegionHistory.EMPTY;
    }
}
