package com.p3.bewoplaner.di;

import com.p3.bewoplaner.BewoplanerApplication;
import com.p3.bewoplaner.data.firebase.DaggerMessagingComponent;
import com.p3.bewoplaner.data.firebase.MessagingComponent;
import com.p3.bewoplaner.page.chat.ChatComponent;
import com.p3.bewoplaner.page.chat.DaggerChatComponent;
import com.p3.bewoplaner.page.contacts.ContactsComponent;
import com.p3.bewoplaner.page.contacts.DaggerContactsComponent;
import com.p3.bewoplaner.page.login.DaggerLoginComponent;
import com.p3.bewoplaner.page.login.LoginComponent;
import com.p3.bewoplaner.page.main.DaggerMainComponent;
import com.p3.bewoplaner.page.main.MainComponent;
import com.p3.bewoplaner.page.profile.DaggerProfileComponent;
import com.p3.bewoplaner.page.profile.ProfileComponent;
import com.p3.bewoplaner.page.splash.DaggerSplashComponent;
import com.p3.bewoplaner.page.splash.SplashComponent;

import android.content.Context;

/**
 * Created by imarneanu on 2/9/17.
 */
public class InjectionHelper {

    private static SplashComponent sSplashComponent;
    private static ContactsComponent sContactsComponent;
    private static LoginComponent sLoginComponent;
    private static MainComponent sMainComponent;
    private static MessagingComponent sMessagingComponent;
    private static ChatComponent sChatComponent;
    private static ProfileComponent sProfileComponent;

    public static ApplicationComponent getApplicationComponent(Context context) {
        return ((BewoplanerApplication) context.getApplicationContext()).getApplicationComponent();
    }

    public static SplashComponent getSplashComponent(Context context) {
        if (sSplashComponent == null) {
            sSplashComponent = DaggerSplashComponent.builder()
                    .applicationComponent(getApplicationComponent(context))
                    .build();
        }
        return sSplashComponent;
    }

    public static LoginComponent getLoginComponent(Context context) {
        if (sLoginComponent == null) {
            sLoginComponent = DaggerLoginComponent.builder()
                    .applicationComponent(getApplicationComponent(context))
                    .build();
        }
        return sLoginComponent;
    }

    public static MainComponent getMainComponent(Context context) {
        if (sMainComponent == null) {
            sMainComponent = DaggerMainComponent.builder()
                    .applicationComponent(getApplicationComponent(context))
                    .build();
        }
        return sMainComponent;
    }

    public static ContactsComponent getContactsComponent(Context context) {
        if (sContactsComponent == null) {
            sContactsComponent = DaggerContactsComponent.builder()
                    .applicationComponent(getApplicationComponent(context))
                    .build();
        }
        return sContactsComponent;
    }

    public static MessagingComponent getMessagingComponent(Context context) {
        if (sMessagingComponent == null) {
            sMessagingComponent = DaggerMessagingComponent.builder()
                    .applicationComponent(getApplicationComponent(context))
                    .build();
        }
        return sMessagingComponent;
    }

    public static ProfileComponent getProfileComponent(Context context) {
        if (sProfileComponent == null) {
            sProfileComponent = DaggerProfileComponent.builder()
                    .applicationComponent(getApplicationComponent(context))
                    .build();
        }
        return sProfileComponent;
    }

    public static ChatComponent getChatComponent(Context context) {
        if (sChatComponent == null) {
            sChatComponent = DaggerChatComponent.builder()
                    .applicationComponent(getApplicationComponent(context))
                    .build();
        }
        return sChatComponent;
    }

    public static void destroySplashComponent() {
        sSplashComponent = null;
    }

    public static void destroyMainComponents() {
        sContactsComponent = null;
        sMainComponent = null;
        sContactsComponent = null;
        sProfileComponent = null;
        sMessagingComponent = null;
    }

    public static void destroyChatComponent() {
        sChatComponent = null;
    }

    public static void destroyLoginComponent() {
        sLoginComponent = null;
    }
}