namespace Indotalent.Shared.Utils;

public static class SequentialGuidGenerator
{
    public static string NewSequentialId()
    {
        byte[] guidBytes = Guid.NewGuid().ToByteArray();

        byte[] timestampBytes = BitConverter.GetBytes(DateTime.UtcNow.Ticks);

        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(timestampBytes);
        }

        guidBytes[10] = timestampBytes[2];
        guidBytes[11] = timestampBytes[3];
        guidBytes[12] = timestampBytes[4];
        guidBytes[13] = timestampBytes[5];
        guidBytes[14] = timestampBytes[6];
        guidBytes[15] = timestampBytes[7];

        return new Guid(guidBytes).ToString();
    }
}