namespace pdinklag
{
    /// <summary>
    /// A yield instruction code.
    /// </summary>
    public struct YieldInstructionCode
    {
        /// <summary>
        /// Tells a coroutine to wait for the next frame.
        /// </summary>
        public static readonly YieldInstructionCode WaitForOneFrame = new(0);

        /// <summary>
        /// Builds a code telling a coroutine to wait for the given number of seconds.
        /// </summary>
        /// <param name="seconds">the number of seconds to wait</param>
        public static YieldInstructionCode Wait(float seconds) => new(((ulong)seconds.ToBits() << 32) | 1UL);

        public static implicit operator ulong(YieldInstructionCode code) => code._code;

        private readonly ulong _code;

        /// <summary>
        /// Constructs a yield instruction.
        /// You should never need this.
        /// </summary>
        /// <param name="code"></param>
        public YieldInstructionCode(ulong code)
        {
            _code = code;
        }
    }
}
