import { Color } from @core:color;

declare host LowGfx {
  [Host(module = "gfx", name = "clear", version = 1)]
  [Capability(name = "gfx")]
  fn clear(color: Color) -> void;

  [Host(module = "gfx", name = "fill_rect", version = 1)]
  [Capability(name = "gfx")]
  fn fill_rect(x: int, y: int, w: int, h: int, color: Color) -> void;

  [Host(module = "gfx", name = "draw_line", version = 1)]
  [Capability(name = "gfx")]
  fn draw_line(x1: int, y1: int, x2: int, y2: int, color: Color) -> void;

  [Host(module = "gfx", name = "draw_circle", version = 1)]
  [Capability(name = "gfx")]
  fn draw_circle(x: int, y: int, r: int, color: Color) -> void;

  [Host(module = "gfx", name = "draw_disc", version = 1)]
  [Capability(name = "gfx")]
  fn draw_disc(x: int, y: int, r: int, border_color: Color, fill_color: Color) -> void;

  [Host(module = "gfx", name = "draw_square", version = 1)]
  [Capability(name = "gfx")]
  fn draw_square(x: int, y: int, w: int, h: int, border_color: Color, fill_color: Color) -> void;

  [Host(module = "gfx", name = "set_sprite", version = 1)]
  [Capability(name = "gfx")]
  fn set_sprite(
    asset_name: str,
    index: int,
    x: int,
    y: int,
    tile_id: int,
    palette_id: int,
    active: bool,
    flip_x: bool,
    flip_y: bool,
    priority: int
  ) -> int;

  [Host(module = "gfx", name = "draw_text", version = 1)]
  [Capability(name = "gfx")]
  fn draw_text(x: int, y: int, message: str, color: Color) -> void;

  [Host(module = "gfx", name = "clear_565", version = 1)]
  [Capability(name = "gfx")]
  fn clear_565(color_565: int) -> void;
}

declare service Gfx
{
    fn clear(color: Color) -> void
    {
        LowGfx.clear(color);
    }

    fn fill_rect(x: int, y: int, w: int, h: int, color: Color) -> void
    {
        LowGfx.fill_rect(x, y, w, h, color);
    }

    fn draw_line(x1: int, y1: int, x2: int, y2: int, color: Color) -> void
    {
        LowGfx.draw_line(x1, y1, x2, y2, color);
    }

    fn draw_circle(x: int, y: int, r: int, color: Color) -> void
    {
        LowGfx.draw_circle(x, y, r, color);
    }

    fn draw_disc(x: int, y: int, r: int, border_color: Color, fill_color: Color) -> void
    {
        LowGfx.draw_disc(x, y, r, border_color, fill_color);
    }

    fn draw_square(x: int, y: int, w: int, h: int, border_color: Color, fill_color: Color) -> void
    {
        LowGfx.draw_square(x, y, w, h, border_color, fill_color);
    }

    fn set_sprite(
        asset_name: str,
        index: int,
        x: int,
        y: int,
        tile_id: int,
        palette_id: int,
        active: bool,
        flip_x: bool,
        flip_y: bool,
        priority: int
    ) -> int
    {
        return LowGfx.set_sprite(asset_name, index, x, y, tile_id, palette_id, active, flip_x, flip_y, priority);
    }

    fn draw_text(x: int, y: int, message: str, color: Color) -> void
    {
        LowGfx.draw_text(x, y, message, color);
    }

    fn clear_565(color_565: int) -> void
    {
        LowGfx.clear_565(color_565);
    }
}
