using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TELTest.Gamemodes {
    public class Classic : QuizGamemode {
        public Classic() {
        }
        public Classic(QuizContainer container, BaseQuizContext context) : base(container, context) {
        }

        public override String Name => "Klasyczny";

        public override String SystemName => "Classic";

        public override String Description => "Klasyczny quizhouse_poor.";

        public override QuizGamemode CreateInstance(QuizContainer quiz, BaseQuizContext context) => new Classic(quiz, context);
        public override async Task Begin() {
            int score = 0;
            await WriteLine("Tytul quizu: " + Quiz.Title);
            await WriteLine("Autor quizu: " + Quiz.Author);
            await WriteLine();
            for (int i = 0; i < Quiz.Questions.Length; i++) {
                await WriteLine((i + 1) + ". " + Quiz.Questions[i].Content);
                string correct = "";
                for (int j = 0; j < Quiz.Questions[i].Answers.Length; j++) {
                    var itm = Quiz.Questions[i].Answers[j];
                    await WriteLine("{0}. {1}", Utilities.NumberToLetter(j).ToLower(), itm.Content);
                    if (itm.Correct) correct += Utilities.NumberToLetter(j).ToUpper()[0];
                }
                await Write("Twoja odpowiedz: ");
                char ans = await ReadUppercaseKey();
                await Flush();
                await WriteLine();
                if (correct.Contains(ans)) {
                    await WriteLine("Dobrze! Zdobywasz punkt.");
                    score++;
                } else {
                    await WriteLine("Zle! Poprawna odpowiedz to: {0}", correct);
                }
                await Write("\r\n\r\n");
            }
            await WriteLine("Twoj wynik: {0}/{1}", score, Quiz.Questions.Length);
            await Pause();

            await DoScoreSubmission(score);
        }

    }
}
