using Radium.DataExporter.Models.Common.Enums;
using Steamworks;

namespace Radium.DataExporter.Client.Platforms;

public class SteamPlatformManager : PlatformManager
{
    public override PlatformType Platform => PlatformType.Steam;

    public override void Initialize()
    {
        if (!SteamAPI.Init())
            throw new Exception($"Failed to initialize {Platform} platform, is {Platform} open and running?");

        PlatformId = $"{SteamUser.GetSteamID()}";
    }

    public override string GetPlatformAuthenticationParamaters()
    {
        var ticketBuffer = new byte[1024];
        var identity = new SteamNetworkingIdentity();
        identity.SetSteamID(SteamUser.GetSteamID());

        var authTicket = SteamUser.GetAuthSessionTicket(ticketBuffer, ticketBuffer.Length, out var ticketSize, ref identity);
        if (authTicket == HAuthTicket.Invalid)
            throw new Exception("Could not get Steam Ticket");

        var ticketHex = Convert.ToHexString(ticketBuffer, 0, (int)ticketSize);

        return ticketHex;
    }
}