

using System;
using UnityEngine;
using Newtonsoft.Json;

namespace com.al_arcade.shared
{


    [Serializable]
    public class ApiResponse<T>
    {
        public bool success;
        public string error;
        public int count;
        public T[] questions;
    }

    [Serializable]
    public class GradesResponse
    {
        public bool success;
        public string error;
        public GradeInfo[] grades;
    }

    [Serializable]
    public class ValidateClassResponse
    {
        public bool success;
        public string error;

        [JsonProperty("class")]
        public ClassInfo classInfo;
    }


    [Serializable]
    public class GradeInfo
    {
        public string id;
        public string name;
    }

    [Serializable]
    public class ClassInfo
    {
        public string id;
        public string class_name;
        public string class_code;
        public string is_active;
        public string grade_id;
        public string grade_name;
        public string teacher_name;
    }


    [Serializable]
    public class McqQuestion
    {
        public string id;
        public string question_text;
        public string answer1;
        public string answer2;
        public string answer3;
        public string answer4;
        public string source;
        public string grade_name;


        public string[] GetShuffledAnswers(out int correctIndex)
        {
            string[] arr = { answer1, answer2, answer3, answer4 };
            string correct = answer1;


            for (int i = arr.Length - 1; i > 0; i--)
            {
                int j = UnityEngine.Random.Range(0, i + 1);
                (arr[i], arr[j]) = (arr[j], arr[i]);
            }

            correctIndex = Array.IndexOf(arr, correct);
            return arr;
        }
    }


    [Serializable]
    public class TfQuestion
    {
        public string id;
        public string question_text;
        public bool is_true;
        public string source;
        public string grade_name;
    }


    [Serializable]
    public class CsQuestion
    {
        public string id;
        public string source;
        public string grade_name;
        public string wrong_word;
        public string correct_answer;
        public CsWord[] words;
        public CsOption[] options;
    }

    [Serializable]
    public class CsWord
    {
        public string word_text;
        public int position;
        public bool is_wrong;
    }

    [Serializable]
    public class CsOption
    {
        public string option_text;
        public bool is_correct;
    }
}
