package org.mercury_im.messenger.data.repository;

import org.mercury_im.messenger.util.Optional;
import org.mercury_im.messenger.entity.Account;
import org.mercury_im.messenger.entity.contact.Peer;

import java.util.List;
import java.util.UUID;

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

public interface PeerRepository {

    Single<Peer> insertPeer(Peer Peer);

    default Observable<Optional<Peer>> observePeer(Peer peer) {
        return observePeer(peer.getId());
    }

    Observable<Optional<Peer>> observePeer(UUID PeerId);

    Maybe<Peer> getPeer(UUID PeerId);

    default Observable<Optional<Peer>> observePeerByAddress(Account account, String address) {
        return observePeerByAddress(account.getId(), address);
    }

    Observable<Optional<Peer>> observePeerByAddress(UUID accountId, String address);

    default Maybe<Peer> getPeerByAddress(Account account, String address) {
        return getPeerByAddress(account.getId(), address);
    }

    Maybe<Peer> getPeerByAddress(UUID accountId, String address);

    Single<Peer> getOrCreatePeer(Account account, String address);

    Single<Peer> getOrCreatePeer(UUID accountId, String address);

    Observable<List<Peer>> observeAllPeers();

    default Observable<List<Peer>> observeAllContactsOfAccount(Account account) {
        return observeAllContactsOfAccount(account.getId());
    }

    Observable<List<Peer>> observeAllContactsOfAccount(UUID accountId);

    Single<Peer> updatePeer(Peer Peer);

    Single<Peer> upsertPeer(Peer Peer);

    Completable deletePeer(Peer Peer);

    Completable deletePeer(UUID accountId, String address);
}
