class Api::StoresController < ApiController
  resource_description do
    short "Stores"
  end

  api :GET, "/api/stores", "List the stores a client can install from"
  desc <<~DESC
    The registry the graphical desktop client reads on first run: which catalogs
    exist, and — where there is one — the repository holding a store's own
    configuration. Public on purpose: a client has nobody to log in as.

    A record needs a name and a catalog URL. `storeRepositoryUrl` is optional and
    answers `null` when there is none; a client then takes identity from this
    record and everything else from the store engine's built-in defaults, so no
    repository has to exist for a store to be installable.
  DESC
  returns code: 200, desc: "Array of stores" do
    property :name, String, desc: "Display name of the store"
    property :catalogUrl, String, desc: "Base URL of the WarpEngine catalog it serves"
    property :storeRepositoryUrl, [String, nil],
             desc: "Repository holding the store's config.json, or null when it has none"
  end
  def index
    render json: StoreService.new.index
  end
end
