package com.example.jmastermind.Deck;

import android.graphics.Color;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

public class DeckCheck implements Deck {
    private List<Integer> deck;
    private Deck lambda;
    private Deck winner;

    /**
     * Permet de comparer une combinaison attaquante avec une combinaison gagnante
     * @param lambda La combinaison attaquante
     * @param winner La combinaison gagnante
     * */
    public DeckCheck(Deck lambda, Deck winner) {
        this.deck = new LinkedList<>();
        this.lambda = lambda;
        this.winner = winner;
    }

    /**
     * Lancement de la verification
     * @return Le deck comprenant les pions de verification Noir et Blanc
     * */
    public Deck doCheck() {
        this.deck = new LinkedList<>();
        List<Integer> winner = this.winner.getDeck();
        List<Integer> lambda = this.lambda.getDeck();

        for(int i = 0; i <= winner.size()-1; i++) {
            Integer win = winner.get(i);
            Integer lam = lambda.get(i);

            if(Objects.equals(win, lam)) {
                this.deck.add(Color.BLACK);
            } else {
                if(winner.contains(lam)) {
                    this.deck.add(Color.WHITE);
                } else {
                    this.deck.add(Color.GRAY);
                }
            }
        }

        Deck check = new DeckLambda(
                this.deck.get(0),
                this.deck.get(1),
                this.deck.get(2),
                this.deck.get(3)
        );

        return check;
    }

    @Override
    public List<Integer> getDeck() {
        return this.deck;
    }

    @Override
    public String displayComb() {
        StringBuilder sb = new StringBuilder();

        for(int i = 0; i <= this.deck.size()-1; i++) {
            switch(this.deck.get(i)) {
                case Color.BLACK: {
                    sb.append("Noir").append(", ");
                    break;
                }

                case Color.WHITE: {
                    sb.append("Blanc").append(", ");
                    break;
                }

                case Color.GRAY: {
                    sb.append("Gris").append(", ");
                    break;
                }

                case Color.GREEN: {
                    sb.append("Vert").append(", ");
                    break;
                }

                case Color.RED: {
                    sb.append("Rouge").append(", ");
                    break;
                }

                case Color.YELLOW: {
                    sb.append("Jaune").append(", ");
                    break;
                }

                case Color.BLUE: {
                    sb.append("Bleu").append(", ");
                    break;
                }
            }
        }

        return sb.toString();
    }
}
