package com.example.jmastermind.Game;

import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.example.jmastermind.Deck.DeckWinner;
import com.example.jmastermind.Events.ColorSelectorEvent;
import com.example.jmastermind.Events.ControlEvent;

public class Controller {
    private Vuew vuew;
    private Model model;
    private AppCompatActivity context;
    private ColorSelectorEvent event;
    private ControlEvent controlEvent;

    /**
     * Controlleur du jeu.
     * @param context Le contexte.
     * @param mode 0 Solo ou 1 multi.
     * @param win Combinaison gagante.
     * */
    public Controller(AppCompatActivity context, int mode,  DeckWinner... win) {
        this.context = context;

        this.controlEvent = new ControlEvent(this.context, this);

        this.model = new Model(this.context);
        this.model.init();

        if(mode == 0) {
            this.model.genWinner();
            DeckWinner winner = this.model.getWinner();
            Log.d("COMBINAISON GAGNANTE", winner.displayComb());
            this.event = new ColorSelectorEvent(this.context, winner);
        } else {
            Log.d("COMBINAISON GAGNANTE", win[0].displayComb());
            this.event = new ColorSelectorEvent(this.context, win[0]);
        }

        this.vuew = new Vuew(
                this.context,
                this.model.getListOfNormalCircle(),
                this.model.getListOfCheckCircle(),
                this.event,
                this.controlEvent
        );

        this.vuew.init();
    }

    /**
     * Quand le joueur appuie sur "valider".
     * */
    public void viewValidate() {
        this.event.goNext();
    }

    /**
     * Quand le joueur appuie sur "effacer".
     * */
    public void viewReset() {
        this.event.resetCombi();
    }
}
