using System.Management;

namespace NcProgramManager.Licensing
{
    internal class MachineFingerprint : IMachineFingerprint
    {
        public string GetFingerprint()
        {
            string pcInfo = string.Empty;

            using (var mc = new ManagementClass("win32_processor"))
            using (ManagementObjectCollection moc = mc.GetInstances())
            {
                foreach (ManagementObject mo in moc)
                {
                    pcInfo = mo.Properties["processorID"]?.Value?.ToString() ?? string.Empty;
                    break;
                }
            }

            using (var searcher = new ManagementObjectSearcher(
                "root\\CIMV2", "SELECT * FROM Win32_BaseBoard"))
            {
                foreach (ManagementObject obj in searcher.Get())
                {
                    pcInfo += obj["SerialNumber"]?.ToString() ?? string.Empty;
                    break;
                }
            }

            return pcInfo;
        }
    }
}
