package com.example.jmastermind.Game;

import android.graphics.Color;
import androidx.appcompat.app.AppCompatActivity;

import com.example.jmastermind.Deck.Deck;
import com.example.jmastermind.Deck.DeckWinner;
import com.example.jmastermind.Events.ColorSelectorEvent;
import com.example.jmastermind.Events.ControlEvent;

import java.util.Random;

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
     * */
    public Controller(AppCompatActivity context, int mode) {
        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();
            Deck winner = this.model.getWinner();
            System.out.println(winner.displayComb());
            this.event = new ColorSelectorEvent(this.context, winner);
        }

        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();
    }
}
