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

import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.region.*;
import de.steamwar.bausystem.region.dynamic.DefaultFlagStorage;
import de.steamwar.bausystem.region.dynamic.NonNormalFlagStorage;
import de.steamwar.bausystem.region.dynamic.RegionDataRepository;
import de.steamwar.bausystem.utils.PasteBuilder;
import lombok.NonNull;
import org.bukkit.Location;

import javax.annotation.Nullable;
import java.io.File;
import java.util.UUID;
import java.util.function.BiConsumer;

public class GlobalRegion implements Region {

    public static final GlobalRegion INSTANCE = new GlobalRegion();

    private static final Point MIN_POINT = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
    private static final Point MAX_POINT = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);

    private static final UUID GLOBAL_REGION_ID = new UUID(0, 0);

    private static final Region.Area GLOBAL_AREA = new Region.Area() {
        @Override
        public @NonNull Point getMinPoint(boolean extension) {
            return MIN_POINT;
        }

        @Override
        public @NonNull Point getMaxPoint(boolean extension) {
            return MAX_POINT;
        }

        @Override
        public @NonNull Point getCopyPoint() {
            return Point.ZERO;
        }

        @Override
        public boolean inRegion(Location location, boolean extension) {
            return true;
        }

        @Nullable
        @Override
        public Clipboard copy(boolean extension) {
            return null;
        }

        @Nullable
        @Override
        public File getResetFile() {
            return null;
        }

        @Override
        public void reset(PasteBuilder pasteBuilder, boolean extension) {
        }

        @Override
        public void forEachChunk(BiConsumer<Integer, Integer> executor) {
        }

        @Override
        public boolean isChunkOutside(int chunkX, int chunkZ) {
            return false;
        }
    };

    private static DefaultFlagStorage FLAG_STORAGE = new NonNormalFlagStorage();
    static {
        RegionDataRepository.loadFlagStorage(INSTANCE, FLAG_STORAGE);
    }

    private GlobalRegion() {
    }

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

    @Override
    public @NonNull UUID getID() {
        return GLOBAL_REGION_ID;
    }

    @Override
    public @NonNull FlagStorage getFlags() {
        return FLAG_STORAGE;
    }

    @Override
    public @NonNull Region.Area getArea() {
        return GLOBAL_AREA;
    }

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

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

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

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

    @Override
    public @NonNull RegionBackups getBackups() {
        return RegionBackups.EMPTY;
    }
}
