package org.mercury_im.messenger.core.data.repository;

import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.jivesoftware.smackx.ox.OpenPgpSecretKeyBackupPassphrase;
import org.jivesoftware.smackx.ox.store.definition.OpenPgpTrustStore;
import org.jxmpp.jid.EntityBareJid;
import org.mercury_im.messenger.core.util.Optional;
import org.mercury_im.messenger.entity.Account;
import org.pgpainless.key.OpenPgpV4Fingerprint;

import java.util.UUID;

import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Single;

public interface IkeyKeyRepository {

    default Observable<Optional<PGPSecretKeyRing>> loadSecretKey(Account account) {
        return loadSecretKey(account.getId());
    }

    Observable<Optional<PGPSecretKeyRing>> loadSecretKey(UUID accountId);

    default Completable storeSecretKey(Account account, PGPSecretKeyRing secretKey) {
        return storeSecretKey(account.getId(), secretKey);
    }

    Completable storeSecretKey(UUID accountId, PGPSecretKeyRing secretKey);

    default Single<Integer> deleteSecretKey(Account account) {
        return deleteSecretKey(account.getId());
    }

    Single<Integer> deleteSecretKey(UUID accountId);

    default Single<Optional<OpenPgpSecretKeyBackupPassphrase>> loadBackupPassphrase(Account account) {
        return loadBackupPassphrase(account.getId());
    }

    Single<Optional<OpenPgpSecretKeyBackupPassphrase>> loadBackupPassphrase(UUID accountID);

    default Completable storeBackupPassphrase(Account account, OpenPgpSecretKeyBackupPassphrase passphrase) {
        return storeBackupPassphrase(account.getId(), passphrase);
    }

    Completable storeBackupPassphrase(UUID accountID, OpenPgpSecretKeyBackupPassphrase passphrase);

    default Observable<Optional<OpenPgpTrustStore.Trust>> loadSuperordinateTrust(Account account, EntityBareJid jid, OpenPgpV4Fingerprint fingerprint) {
        return loadSuperordinateTrust(account.getId(), jid, fingerprint);
    }

    Observable<Optional<OpenPgpTrustStore.Trust>> loadSuperordinateTrust(UUID accountId, EntityBareJid jid, OpenPgpV4Fingerprint fingerprint);

    default Completable storeSuperordinateTrust(Account account, EntityBareJid jid, OpenPgpV4Fingerprint fingerprint, OpenPgpTrustStore.Trust trust) {
        return storeSuperordinateTrust(account.getId(), jid, fingerprint, trust);
    }

    Completable storeSuperordinateTrust(UUID accountId, EntityBareJid jid, OpenPgpV4Fingerprint fingerprint, OpenPgpTrustStore.Trust trust);
}
