﻿#region Header

// Copyright (c) 2025 AccelByte Inc. All Rights Reserved.
// This is licensed software from AccelByte Inc, for limitations
// and restrictions contact your company contract manager.

#endregion

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Windows;
using AOT;

namespace BlackBox
{


    // Define a delegate matching the method signature

    // Apply the MonoPInvokeCallback attribute
    

    [Serializable]
    public struct Helper
    {


        private static bool IsThirdPartyAssigned = false;


        [MonoPInvokeCallback(typeof(PluginAPI.GenerateDeviceIDCallback))]        
        public static void BBXGenerateDeviceIDCallback(IntPtr buffer_device_id, int buffer_size)
        {
            string _device_id = SystemInfo.deviceUniqueIdentifier;
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(_device_id);

            var size = Math.Min(bytes.Length, buffer_size - 1);
            Marshal.Copy(bytes, 0, buffer_device_id, size);
            Marshal.WriteByte(buffer_device_id, size, 0);

            Logger.Log("Generated Device ID: " + _device_id);
        }

        public static void BBXSetThirdPartyAccount(string platform, string id, string username, string email)
        {
            /**
            * @param platform Thirdparty platform. Value (in lowercase): steam, epic, psn, xboxlive, nintendo
            * @param id Thirdparty account id
            * @param username Thirdparty account username
            * @param email Thirdparty account email address
            *
            * @return bool Success or fail setting the thirdparty account
            */
            if (IsThirdPartyAssigned == false)
            {
                PluginAPI.bbx_set_thirdparty_account(platform, id, username, email);
                IsThirdPartyAssigned = true;
            }
        }
    }
}