// Path: src/main/java/org/nextrtc/signalingserver/repository/ConversationRepository.java
// public interface ConversationRepository extends Closeable {
//     Optional<Conversation> findBy(String id);
// 
//     Optional<Conversation> findBy(Member from);
// 
//     Conversation remove(String id);
// 
//     Conversation save(Conversation conversation);
// 
//     Collection<String> getAllIds();
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/repository/Conversations.java
// @Slf4j
// @Repository
// public class Conversations implements ConversationRepository {
// 
//     private Map<String, Conversation> conversations = Maps.newConcurrentMap();
// 
//     @Override
//     public Optional<Conversation> findBy(String id) {
//         if (isEmpty(id)) {
//             return Optional.empty();
//         }
//         return Optional.ofNullable(conversations.get(id));
//     }
// 
//     @Override
//     public Optional<Conversation> findBy(Member from) {
//         return conversations.values().stream().filter(conversation -> conversation.has(from)).findAny();
//     }
// 
//     @Override
//     public Conversation remove(String id) {
//         return conversations.remove(id);
//     }
// 
//     @Override
//     public Conversation save(Conversation conversation) {
//         if (conversations.containsKey(conversation.getId())) {
//             throw CONVERSATION_NAME_OCCUPIED.exception();
//         }
//         conversations.put(conversation.getId(), conversation);
//         return conversation;
//     }
// 
//     @Override
//     public Collection<String> getAllIds() {
//         return conversations.keySet();
//     }
// 
//     @Override
//     public void close() throws IOException {
//         for (Conversation conversation : conversations.values()) {
//             try {
//                 conversation.close();
//             } catch (Exception e) {
//                 log.error("Problem during closing conversation " + conversation.getId(), e);
//             }
//         }
//     }
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/repository/MemberRepository.java
// public interface MemberRepository extends Closeable{
//     Collection<String> getAllIds();
// 
//     Optional<Member> findBy(String id);
// 
//     Member register(Member member);
// 
//     void unregister(String id);
// 
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/repository/Members.java
// @Slf4j
// @Repository
// public class Members implements MemberRepository {
// 
//     private Map<String, Member> members = Maps.newConcurrentMap();
// 
//     @Override
//     public Collection<String> getAllIds() {
//         return members.keySet();
//     }
// 
//     @Override
//     public Optional<Member> findBy(String id) {
//         if (id == null) {
//             return Optional.empty();
//         }
//         return Optional.ofNullable(members.get(id));
//     }
// 
//     @Override
//     public Member register(Member member) {
//         if (!members.containsKey(member.getId())) {
//             members.put(member.getId(), member);
//         }
//         return member;
//     }
// 
//     @Override
//     public void unregister(String id) {
//         findBy(id).ifPresent(Member::markLeft);
//         Member removed = members.remove(id);
//         if (removed != null) {
//             removed.getConversation().ifPresent(c -> c.left(removed));
//         }
//     }
// 
//     @Override
//     public void close() throws IOException {
//         for (Member member : members.values()) {
//             try {
//                 member.getConnection().close();
//             } catch (Exception e) {
//                 log.error("Problem during closing member connection " + member.getId(), e);
//             }
//         }
//         members.clear();
//     }
// }


import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import org.nextrtc.signalingserver.repository.ConversationRepository;
import org.nextrtc.signalingserver.repository.Conversations;
import org.nextrtc.signalingserver.repository.MemberRepository;
import org.nextrtc.signalingserver.repository.Members;
import javax.inject.Singleton;
package org.nextrtc.signalingserver.modules;



@Module
public abstract class NextRTCRepositories {

    @Provides
    @Singleton
    static Members Members() {
        return new Members();
    }

    @Provides
    @Singleton
    static Conversations Conversations() {
        return new Conversations();
    }

    @Binds
// Path: src/main/java/org/nextrtc/signalingserver/repository/ConversationRepository.java
// public interface ConversationRepository extends Closeable {
//     Optional<Conversation> findBy(String id);
// 
//     Optional<Conversation> findBy(Member from);
// 
//     Conversation remove(String id);
// 
//     Conversation save(Conversation conversation);
// 
//     Collection<String> getAllIds();
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/repository/Conversations.java
// @Slf4j
// @Repository
// public class Conversations implements ConversationRepository {
// 
//     private Map<String, Conversation> conversations = Maps.newConcurrentMap();
// 
//     @Override
//     public Optional<Conversation> findBy(String id) {
//         if (isEmpty(id)) {
//             return Optional.empty();
//         }
//         return Optional.ofNullable(conversations.get(id));
//     }
// 
//     @Override
//     public Optional<Conversation> findBy(Member from) {
//         return conversations.values().stream().filter(conversation -> conversation.has(from)).findAny();
//     }
// 
//     @Override
//     public Conversation remove(String id) {
//         return conversations.remove(id);
//     }
// 
//     @Override
//     public Conversation save(Conversation conversation) {
//         if (conversations.containsKey(conversation.getId())) {
//             throw CONVERSATION_NAME_OCCUPIED.exception();
//         }
//         conversations.put(conversation.getId(), conversation);
//         return conversation;
//     }
// 
//     @Override
//     public Collection<String> getAllIds() {
//         return conversations.keySet();
//     }
// 
//     @Override
//     public void close() throws IOException {
//         for (Conversation conversation : conversations.values()) {
//             try {
//                 conversation.close();
//             } catch (Exception e) {
//                 log.error("Problem during closing conversation " + conversation.getId(), e);
//             }
//         }
//     }
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/repository/MemberRepository.java
// public interface MemberRepository extends Closeable{
//     Collection<String> getAllIds();
// 
//     Optional<Member> findBy(String id);
// 
//     Member register(Member member);
// 
//     void unregister(String id);
// 
// }
// 
// Path: src/main/java/org/nextrtc/signalingserver/repository/Members.java
// @Slf4j
// @Repository
// public class Members implements MemberRepository {
// 
//     private Map<String, Member> members = Maps.newConcurrentMap();
// 
//     @Override
//     public Collection<String> getAllIds() {
//         return members.keySet();
//     }
// 
//     @Override
//     public Optional<Member> findBy(String id) {
//         if (id == null) {
//             return Optional.empty();
//         }
//         return Optional.ofNullable(members.get(id));
//     }
// 
//     @Override
//     public Member register(Member member) {
//         if (!members.containsKey(member.getId())) {
//             members.put(member.getId(), member);
//         }
//         return member;
//     }
// 
//     @Override
//     public void unregister(String id) {
//         findBy(id).ifPresent(Member::markLeft);
//         Member removed = members.remove(id);
//         if (removed != null) {
//             removed.getConversation().ifPresent(c -> c.left(removed));
//         }
//     }
// 
//     @Override
//     public void close() throws IOException {
//         for (Member member : members.values()) {
//             try {
//                 member.getConnection().close();
//             } catch (Exception e) {
//                 log.error("Problem during closing member connection " + member.getId(), e);
//             }
//         }
//         members.clear();
//     }
// }


// Path: src/main/java/org/nextrtc/signalingserver/modules/NextRTCRepositories.java
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import org.nextrtc.signalingserver.repository.ConversationRepository;
import org.nextrtc.signalingserver.repository.Conversations;
import org.nextrtc.signalingserver.repository.MemberRepository;
import org.nextrtc.signalingserver.repository.Members;
import javax.inject.Singleton;

package org.nextrtc.signalingserver.modules;



@Module
public abstract class NextRTCRepositories {

    @Provides
    @Singleton
    static Members Members() {
        return new Members();
    }

    @Provides
    @Singleton
    static Conversations Conversations() {
        return new Conversations();
    }

    @Binds
    abstract ConversationRepository conversationRepository(Conversations conversations);