using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using BACKND;
public class BackndFriend {
private static BackndFriend _instance = null;
public static BackndFriend Instance {
get {
if(_instance == null) {
_instance = new BackndFriend();
}
return _instance;
}
}
private List<Tuple<string, string>> _requestFriendList = new List<Tuple<string, string>>();
public void SendFriendRequest(string nickName) {
var inDateBro = Backnd.Player.GetPlayerInfoByDisplayName(nickName);
if(inDateBro.IsSuccess() == false) {
Debug.LogError("An error occurred while searching the name of the user. : " + inDateBro);
return;
}
string inDate = inDateBro.GetReturnValuetoJSON()["row"]["inDate"].ToString();
Debug.Log($"inDate value of {nickName} is {inDate}.");
var friendBro = Backnd.Friend.SendFriendRequest(inDate);
if(friendBro.IsSuccess() == false) {
Debug.LogError($"{inDate} An error occurred while sending a friend request. : " + friendBro);
return;
}
Debug.Log("Friend request sent successfully." + friendBro);
}
public void GetReceivedSendFriendRequest() {
var bro = Backnd.Friend.GetUnresolvedFriendRequestList();
if(bro.IsSuccess() == false) {
Debug.Log("An error occurred while loading the received friend requests list. : " + bro);
return;
}
if(bro.FlattenRows().Count <= 0) {
Debug.LogError("There are no received friend requests.");
return;
}
Debug.Log("Successfully loaded the received friend requests list. : " + bro);
int index = 0;
foreach(BACKND.LitJson.JsonData friendJson in bro.FlattenRows()) {
string nickName = friendJson["nickname"]?.ToString();
string inDate = friendJson["inDate"].ToString();
_requestFriendList.Add(new Tuple<string, string>(nickName, inDate));
Debug.Log($"{index}. {nickName} - {inDate}");
index++;
}
}
public void ApplyFriend(int index) {
if(_requestFriendList.Count <= 0) {
Debug.LogError("There are no friend requests.");
return;
}
if(index >= _requestFriendList.Count) {
Debug.LogError($"Exceeded the limit of the received friend request list. Select : {index} / List maximum : {_requestFriendList.Count}");
return;
}
var bro = Backnd.Friend.AcceptFriendRequest(_requestFriendList[index].Item2);
if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while accepting the friend request. : " + bro);
return;
}
Debug.Log($"{_requestFriendList[index].Item1} has become a friend. : " + bro);
}
public void GetFriendList() {
var bro = Backnd.Friend.GetFriendList();
if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while loading the friends list. : " + bro);
return;
}
Debug.Log("Successfully loaded the friends list. : " + bro);
if(bro.FlattenRows().Count <= 0) {
Debug.Log("There are no friends.");
return;
}
int index = 0;
string friendListString = "Friends List\n";
foreach(BACKND.LitJson.JsonData friendJson in bro.FlattenRows()) {
string nickName = friendJson["nickname"]?.ToString();
string inDate = friendJson["inDate"].ToString();
friendListString += $"{index}. {nickName} - {inDate}\n";
index++;
}
Debug.Log(friendListString);
}
}