using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManagerScript : MonoBehaviour {

    private int playerCount;
    private string gameMode;

    public Database db;
    StatsScript statsScript;
     
    public string GameMode { get => gameMode; set => gameMode = value; }
    public int GameId { get; internal set; }

    List<KeyValuePair<string, int>> players;
    // Start is called before the first frame update
    void Start() {
        db = Database.Instance;
        GameId = PlayerPrefs.GetInt("GameId");

        db.SetLocalOrOnline("Local");
        db.SetLastPlayedDate(GameId);
        statsScript = GameObject.Find("StatsPanel").GetComponent<StatsScript>();

    }

    private List<KeyValuePair<string,int>> GetPlayersForGame() {
        players = db.GetPlayersForGame(GameId);
        return players;
    }

    public void UpdateQuestiosLost(int questionsLost, string playerName) {
        db.SetQuestionsLost(GameId, playerName, questionsLost);
    }

    public void UpdateQuestionsInAnswerLine(string playerName, int count) {
        
    }

    public List<KeyValuePair<string, int>> GetPlayers() {
        if (players == null) {
            players = GetPlayersForGame();
        }
        return players;
    }

}
