using CosmicDriver;

// Integration example only. This is not an official C# SDK.
using var sdk = new CosmicSdk(2000);

if (!sdk.Connect())
{
    throw new Exception("Failed to connect to a Binho device.");
}

var (status, info) = sdk.GetDeviceInfo();
AssertStatus(status, "GetDeviceInfo");
Console.WriteLine($"Manufacturer: {info!.Manufacturer}");
Console.WriteLine($"Product name: {info.ProductName}");
Console.WriteLine($"Serial number: {info.SerialNumber}");
Console.WriteLine($"FW version: {info.FwVersion}");
Console.WriteLine($"HW version: {info.HwVersion}");

AssertStatus(sdk.EnterBootMode(), "EnterBootMode");
Console.WriteLine("Boot mode command sent successfully");

static void AssertStatus(ResultCode status, string operation, params ResultCode[] expected)
{
    if (expected.Length == 0)
    {
        expected = [ResultCode.SUCCESS];
    }
    if (!expected.Contains(status))
    {
        throw new Exception($"{operation} failed. STATUS=0x{(ushort)status:X4}. Expected: {string.Join(", ", expected.Select(e => $"0x{(ushort)e:X4}"))}");
    }
}
