using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using CBLP.VPSService;
using System;
using XenseAR;

public class XenseTrackingManager : MonoBehaviour
{
    [SerializeField] Text msgText;
    [SerializeField] VPSLocalisationService localisationService;
    // Start is called before the first frame update

    private void Awake()
    {
        if (localisationService != null)
        {
            localisationService.OnLocalisationStatusChange += (status) =>
        {
            HandleHlocLocationStateChange(status);
        };
        }
    }

    private void HandleHlocLocationStateChange(LocalisationResponse response)
    {
        IResponseAdapter responseAdapter = new CBLPResponseAdapter(response);
        LocalizationResponse localizationResponse = responseAdapter.Convert();
        HandleLocalizationStatusChange(localizationResponse);
    }

    private void HandleLocalizationStatusChange(LocalizationResponse response)
    {
        switch (response.Status)
        {
            case LocalizationStatus.Found:
                msgText.text = "Localize status: Found";
                break;
            case LocalizationStatus.NotFound:
                msgText.text = "Localize status: Not Found";
                break;
            case LocalizationStatus.QpsLimitExceeded:
                msgText.text = "Localize status: Qps Limit Exceeded";
                break;
            case LocalizationStatus.RequestTimeout:
                msgText.text = "Localize status: Request Timeout";
                break;
            case LocalizationStatus.RequestIntervalTooLow:
                msgText.text = "Localize status: Request Interval Too Low";
                break;
            case LocalizationStatus.UnknownError:
                msgText.text = "Localize status: Unknown Error";
                break;
            case LocalizationStatus.WakingUp:
                msgText.text = "Localize status: Waking up";
                break;
        }
    }
}
