 
   defp draw_row(board, row) do
     first_row = 0
-    last_row = size_of_raw(board) - 1
+    last_row = size(board) - 1
     label =
       case row do
         ^first_row -> "  "

  @moduledoc """
  """

  alias LexibombServer.Board.Square

  @default_size 15
  @bomb_count 22

  def new(size \\ @default_size) do
    empty_board(size)
  end

  def empty_board(size) do
    border = 2
    total_squares = (size + border) * (size + border)
    board = for _ <- 1..total_squares, do: %Square{}
    board |> deactivate_border
  end

  defp deactivate_border(board) do
    size = size_of_raw(board)
    board
    |> Enum.with_index
    |> Enum.map(fn {square, index} ->
         case border_square?(size, index) do
           true -> Square.deactivate(square)
           false -> square
         end
       end)
  end

  defp border_square?(size, index) do
    cond do
      first_row?(size, index) ->
        true
      last_row?(size, index) ->
        true
      first_col?(size, index) ->
        true
      last_col?(size, index) ->
        true
      true ->
        false
    end
  end

  defp first_row?(size, index), do: index < size
  defp last_row?(size, index), do: index >= (size * (size - 1))
  defp first_col?(size, index), do: rem(index, size) === 0
  defp last_col?(size, index), do: rem(index, size) === size - 1

  def debug(device \\ :stdio, board) do
    size = size_of_raw(board)
    border = 2

    header = draw_header(size - border)

  end

  defp draw_all_rows(board) do
    size = size(board)
    grid_line = draw_grid_line(size, :middle)
    rows = for row <- 0..size-1, do: draw_row(board, row)
    rows |> Enum.join(grid_line)
