/*
 * 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 de.steamwar.bausystem.region.FlagOptional;
import de.steamwar.bausystem.region.RegionFlagPolicy;
import de.steamwar.bausystem.region.flags.ColorMode;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.ProtectMode;
import de.steamwar.bausystem.region.flags.TNTMode;
import de.steamwar.core.Core;
import lombok.NonNull;
import lombok.ToString;

@ToString
public class NonNormalFlagStorage extends DefaultFlagStorage {

    public NonNormalFlagStorage() {
        flagMap.put(Flag.TNT, TNTMode.DENY);
    }

    @Override
    public @NonNull <T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy has(@NonNull Flag<T> flag) {
        if (flag.oneOf(Flag.COLOR)) {
            return RegionFlagPolicy.READ_ONLY;
        }
        if (flag.oneOf(Flag.ITEMS) && Core.getVersion() >= 20) {
            return RegionFlagPolicy.WRITABLE;
        }
        if (flag.oneOf(Flag.TNT, Flag.FIRE, Flag.FREEZE)) {
            return RegionFlagPolicy.WRITABLE;
        }
        return RegionFlagPolicy.NOT_APPLICABLE;
    }

    @Override
    public @NonNull <T extends Enum<T> & Flag.Value<T>> FlagOptional<T> get(@NonNull Flag<T> flag) {
        if (flag.oneOf(Flag.COLOR)) {
            return FlagOptional.of((Flag) flag, ColorMode.YELLOW);
        }
        if (flag.oneOf(Flag.PROTECT)) {
            return FlagOptional.of((Flag) flag, ProtectMode.INACTIVE);
        }
        return super.get(flag);
    }
}
