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

public static class DataManager{
    public const string API_Endpoint="https://109-237-27-65.ip.linodeusercontent.com/pogemoon/api/";
    private static string username;
    public static string Username{get{
        if(PlayerPrefs.HasKey("username")){
            return PlayerPrefs.GetString("username");
        }else{
            return "";
        }
    }
    set{
        PlayerPrefs.SetString("username",value);
        PlayerPrefs.Save();
    }}
    public static bool LoggedIn {get{return PlayerPrefs.HasKey("username");}}

   
    public static int best{
        get{
            return (int)PlayerPrefs.GetFloat("best");
        }
        set{
            PlayerPrefs.SetFloat("best", value);
            PlayerPrefs.Save();
        }
    }

    public static bool OnLoginDone(string username,string response){
        int uid = -1;
        try{
            uid = int.Parse(response);
        }catch{
            Debug.LogError("Error in registering : " + response);
        }


        if(uid >=0){
            Username = username +"#"+ uid;
            PlayerPrefs.SetString("username", Username);
            PlayerPrefs.Save();

            return true;
        }


        return false;
    }  
}