#Requires -Version 7.4

<#
.SYNOPSIS
    Defines native Windows API types for vSEAL module.

.DESCRIPTION
    Contains P/Invoke definitions for Windows native APIs used by vSEAL functions.
    These types are used by Get-vSEALOperatingSystemInfo for full OS detection.

.NOTES
    This file is dot-sourced by the module loader.
#>

# Only define types once per session
if (-not ('vSEAL.Native.NativeMethods' -as [type])) {
    Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;

namespace vSEAL.Native
{
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct OSVERSIONINFOEXW
    {
        public uint dwOSVersionInfoSize;
        public uint dwMajorVersion;
        public uint dwMinorVersion;
        public uint dwBuildNumber;
        public uint dwPlatformId;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
        public string szCSDVersion;
        public ushort wServicePackMajor;
        public ushort wServicePackMinor;
        public ushort wSuiteMask;
        public byte wProductType;
        public byte wReserved;
    }

    public static class NativeMethods
    {
        [DllImport("ntdll.dll")]
        public static extern int RtlGetVersion(ref OSVERSIONINFOEXW versionInfo);

        [DllImport("kernel32.dll")]
        public static extern bool GetProductInfo(
            uint dwOSMajorVersion,
            uint dwOSMinorVersion,
            uint dwSpMajorVersion,
            uint dwSpMinorVersion,
            out uint pdwReturnedProductType);
    }

    [Flags]
    public enum SuiteMask : ushort
    {
        VER_SUITE_SMALLBUSINESS = 0x0001,
        VER_SUITE_ENTERPRISE = 0x0002,
        VER_SUITE_BACKOFFICE = 0x0004,
        VER_SUITE_TERMINAL = 0x0010,
        VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x0020,
        VER_SUITE_EMBEDDEDNT = 0x0040,
        VER_SUITE_DATACENTER = 0x0080,
        VER_SUITE_SINGLEUSERTS = 0x0100,
        VER_SUITE_PERSONAL = 0x0200,
        VER_SUITE_BLADE = 0x0400,
        VER_SUITE_STORAGE_SERVER = 0x2000,
        VER_SUITE_COMPUTE_SERVER = 0x4000,
        VER_SUITE_WH_SERVER = 0x8000
    }

    public enum ProductType : byte
    {
        VER_NT_WORKSTATION = 1,
        VER_NT_DOMAIN_CONTROLLER = 2,
        VER_NT_SERVER = 3
    }
}
'@
}
