defmodule AstralWeb.StorefrontController do
  use AstralWeb, :controller

  def keychain(conn, _params) do
    file_path = Path.join(["assets", "keychain.json"])

    case File.read(file_path) do
      {:ok, content} ->
        case Jason.decode(content) do
          {:ok, json} ->
            conn
            |> put_status(200)
            |> json(json)

          {:error, _} ->
            conn
            |> put_status(500)
            |> json(%{error: "Failed to decode JSON"})
        end

      {:error, _} ->
        conn
        |> put_status(500)
        |> json(%{error: "Failed to read file"})
    end
  end


  def receipts(conn, %{"accountId" => _account_id}) do 
    conn
    |> put_status(200)
    |> json([])
  end

  def offers(conn, %{"accountId" => _account_id}) do 
    conn
    |> put_status(200)
    |> json([])
  end
  
def catalog(conn, _params) do
    file_path = Path.join(["assets", "catalog.json"])

    case File.read(file_path) do
      {:ok, content} ->
        case Jason.decode(content) do
          {:ok, json} ->
            conn
            |> put_status(200)
            |> json(json)

          {:error, _} ->
            conn
            |> put_status(500)
            |> json(%{error: "Failed to decode JSON"})
        end

      {:error, _} ->
        conn
        |> put_status(500)
        |> json(%{error: "Failed to read file"})
    end
  end
end
