using System.Runtime.InteropServices;

namespace Pilz.Win32.Native;


[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
    public int Left;
    public int Top;
    public int Right;
    public int Bottom;

    public RECT(int left_, int top_, int right_, int bottom_)
    {
        Left = left_;
        Top = top_;
        Right = right_;
        Bottom = bottom_;
    }

    public RECT(Rectangle r)
    {
        Left = r.Left;
        Top = r.Top;
        Right = r.Right;
        Bottom = r.Bottom;
    }

    public int Height
    {
        get
        {
            return Bottom - Top;
        }
    }

    public int Width
    {
        get
        {
            return Right - Left;
        }
    }

    public Size Size
    {
        get
        {
            return new Size(Width, Height);
        }
    }

    public Point Location
    {
        get
        {
            return new Point(Left, Top);
        }
    }

    public Rectangle ToRectangle()
    {
        return Rectangle.FromLTRB(Left, Top, Right, Bottom);
    }

    public static RECT FromRectangle(Rectangle rectangle)
    {
        return new RECT(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
    }

    public override int GetHashCode()
    {
        return (int)Math.Round(Math.Pow(Math.Pow(Math.Pow(Left, Top << 13 | Top >> 0x13), Width << 0x1A | Width >> 6), Height << 7 | Height >> 0x19));

    }

    public static RECT FromXYWH(int x, int y, int width, int height)
    {
        return new RECT(x, y, x + width, y + height);
    }

    public static implicit operator Rectangle(RECT rect)
    {
        return Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom);
    }

    public static implicit operator RECT(Rectangle rect)
    {
        return new RECT(rect.Left, rect.Top, rect.Right, rect.Bottom);
    }

    public override string ToString()
    {
        return "Left=" + Left + ", Top=" + Top + ", Right=" + Right + ", Bottom=" + Bottom;
    }
}