/*
 * This file is part of Bisq.
 *
 * Bisq 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.
 *
 * Bisq 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 Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package bisq.core.dao.governance.blindvote.storage;

import bisq.network.p2p.storage.P2PDataStorage;
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
import bisq.network.p2p.storage.persistence.MapStoreService;

import bisq.common.config.Config;
import bisq.common.storage.Storage;

import javax.inject.Named;
import javax.inject.Inject;

import java.io.File;

import java.util.Map;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BlindVoteStorageService extends MapStoreService<BlindVoteStore, PersistableNetworkPayload> {
    private static final String FILE_NAME = "BlindVoteStore";

    // At startup it is true, so the data we receive from the seed node are not checked against the phase as we have
    // not started up the DAO domain at that moment.
    @Setter
    private boolean notInVoteRevealPhase = true;


    ///////////////////////////////////////////////////////////////////////////////////////////
    // Constructor
    ///////////////////////////////////////////////////////////////////////////////////////////

    @Inject
    public BlindVoteStorageService(@Named(Config.STORAGE_DIR) File storageDir,
                                   Storage<BlindVoteStore> persistableNetworkPayloadMapStorage) {
        super(storageDir, persistableNetworkPayloadMapStorage);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    // API
    ///////////////////////////////////////////////////////////////////////////////////////////

    @Override
    public String getFileName() {
        return FILE_NAME;
    }

    @Override
    public Map<P2PDataStorage.ByteArray, PersistableNetworkPayload> getMap() {
        return store.getMap();
    }

    @Override
    public boolean canHandle(PersistableNetworkPayload payload) {
        return payload instanceof BlindVotePayload && notInVoteRevealPhase;
    }


    ///////////////////////////////////////////////////////////////////////////////////////////
    // Protected
    ///////////////////////////////////////////////////////////////////////////////////////////

    @Override
    protected BlindVoteStore createStore() {
        return new BlindVoteStore();
    }
}

@@ -962,23 +962,38 @@
 mon.
-storage.Stor
+persistence.PersistenceMan
 age
+r
 ;%0A%0Ai
@@ -1011,21 +1011,22 @@
 .inject.
-Named
+Inject
 ;%0Aimport
@@ -1039,22 +1039,21 @@
 .inject.
-Inject
+Named
 ;%0A%0Aimpor
@@ -1896,23 +1896,34 @@
         
-Stor
+PersistenceMan
 age
+r
 %3CBlindVo
@@ -1942,36 +1942,19 @@
 sist
-ableNetworkPayloadMapStor
+enceMan
 age
+r
 ) %7B%0A
@@ -1990,36 +1990,19 @@
 sist
-ableNetworkPayloadMapStor
+enceMan
 age
+r
 );%0A 

Use PersistenceManager