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

public class SetInfo : MonoBehaviour
{
    public ADokManager adok;
    public Text txtResult;

    public InputField inpPhoneno;
    public InputField inpcodeTaied;

    public InputField inpUserName;
    public InputField inpNickName;
    // Use this for initialization
    void Start()
    {
        adok.OnChangeNickName += Adok_OnChangeNickName;
        adok.OnChangeUsernameChange += Adok_OnChangeUsernameChange;
        adok.OnSetPhoneNoChange += Adok_OnSetPhoneNoChange;
        adok.OnCodeTaiedSetPhoneNoChange += Adok_OnCodeTaiedSetPhoneNoChange;
        adok.OnResendCodeTaiedChange += Adok_OnResendCodeTaiedChange;
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void ChangeNickName()
    {
        adok.ChangeNickName(inpNickName.text);
    }

    private void Adok_OnChangeNickName(ADokManager.ChangeNickNameResult changeNickNameResult)
    {
        txtResult.text = "changeNickNameResult: " + changeNickNameResult.ToString();
    }

    public void ChangeUsername()
    {
        adok.ChangeUsername(inpUserName.text);
    }

    private void Adok_OnChangeUsernameChange(ADokManager.ChangeUsernameResult cmResult)
    {
        txtResult.text = "ChangeUsernameResult: " + cmResult.ToString();
    }

    public void SetPhoneNoChange()
    {
        adok.SetPhoneNo(inpPhoneno.text);
    }

    public void setCodeTaied()
    {
        adok.SetPhoneNoCheckCodeTaied(inpcodeTaied.text);
    }

    public void resendCodeTaied()
    {
        adok.ResendCodeTaied();
    }

    private void Adok_OnResendCodeTaiedChange(ADokManager.CodeTaiedResult CodeTaiedResult)
    {
        int mustWaitTime = (int)(60 - adok.delayNeeded);
        if (mustWaitTime < 0)
        {
            mustWaitTime = 0;
        }
        txtResult.text = "CodeTaiedResult:" + CodeTaiedResult.ToString() + " --- mustWaitTime:" + mustWaitTime;
    }

    private void Adok_OnCodeTaiedSetPhoneNoChange(ADokManager.CodeTaiedResult CodeTaiedResult)
    {
        txtResult.text = "CodeTaiedResult: " + CodeTaiedResult.ToString();
    }

    private void Adok_OnSetPhoneNoChange(ADokManager.SetPhoneNoResult cmResult)
    {
        txtResult.text = "SetPhoneNoResult: " + cmResult.ToString();
    }
}
