## Context
**馃搷KR: In order to better understand the needs of our users on the visibility of the Wikibase instances available on the ecosystem, we deliver a prototype, by the end of Q2, that facilitates ecosystem-wide discovery of stable Wikibases that are intended for federation and reuse by wider audiences.**
The Suite team is building a prototype for a tool that facilitates discovery of Wikibases in the ecosystem (analog of Cloud's [[ https://www.wikibase.cloud/discovery | discovery page ]], but with known Suite instances included). The scope of the prototype includes possibility to recognize instances that are intended by their managers for federation and reuse by wider audiences.
As part of the data governance process, the Cloud team is planning to implement [a question](https://docs.google.com/document/d/1Vdsfwj7M8lkoNu1bA1HC4CRfipd3yW5UblgH0DTq3-s/edit?tab=t.kyvu5vllt69#bookmark=id.3fbfn67vmk7e) that explicitly asks the manager whether they believe the instance is intended for reuse / intended, but not ready for reuse / not intended for reuse / unsure. This work is planned when the Wiki profile implementation starts (see [Iteration 1](https://docs.google.com/document/d/1Vdsfwj7M8lkoNu1bA1HC4CRfipd3yW5UblgH0DTq3-s/edit?tab=t.pnbwvcbn5tvh#bookmark=id.ebs64dyh5k4v)).
Until then, for the purposes of the prototype, we would like to return a flag that is an approximation of the manager's intent based on the data we already collect in the **Intended Use** section of the wiki profile:
- data hub
- permanent
- intended for wider audience.
The prototype currently gets metadata on Cloud instances from the Cloud's discovery page API.
## Story
As a reuser navigating the Wikibase Ecosystem,
I would like to discover and recognize instances intended for reuse and federation by their managers,
In order to understand which data I can confidently rely on in my projects.
## Acceptance Criteria
[] The [discovery page API](https://www.wikibase.cloud/api/wiki?sort=pages&direction=desc&page=1&per_page=2000) returns one additional flag per instance: `reuse_prototype`.
[] The flag is 1/true if the instance has:
- purpose = data_hub AND
- lifespan = permanent AND
- audience = wide
[] The flag is 0/false otherwise.
## Notes
- The flag will be replaced in the future with the one reflecting the answer of the manager to an explicit question. We might also choose to expose it through a different API. This solution is temporary and good enough for the prototype for now to support Suite achieve their learning goals when they validate the prototype with users.
- The intended use data is stored in `wiki_profiles` table - look for the most recent record for the given `wiki_id`.
## Pre-Breakdown
* [PublicWikiController](https://github.com/wbstack/api/blob/main/app/Http/Controllers/PublicWikiController.php) is where the current logic lives
* Also see [PublicWikiResource](https://github.com/wbstack/api/blob/main/app/Http/Resources/PublicWikiResource.php)
* Do we want to use [Wiki::wikiLatestProfile()](https://github.com/wbstack/api/blob/main/app/Wiki.php#L159) or follow the existing pattern and use a `->join()`?
* We want to be cautious of query explosion when looking up these profiles. This [article](https://inspector.dev/logging-database-queries-with-eloquent-orm-and-laravel-fast-tips/) shows some possible ways to log the queries.
* We should add a limit to the `per_page` query parameter of `100`.
* What do we mean by "flag"? A new query parameter in the request that //filters// the results? OR a new field in the results. We have asked the Suite engineers for what they require: https://mattermost.wikimedia.de/swe/pl/378zfs5m57bs3fp4saff74z1py
## Task Breakdown
We noted that we haven't had an answer from Suite yet about what their requirements are. We will break down both possibilities.
* We want a query parameter to enable or disable this feature. It should be disabled by default. `enable_suite_reuse_prototype=true/false`.
* Add a `reuse_prototype` field to `PublicWikiResource` that is boolean or null; probably following the same pattern as the `logo_url`
* If a new field in the output is required
- Add a conditional to check if the `enable_suite_reuse_prototype` query parameter is true
- If it is true, use something like `$query->leftJoinWhere()` to join on the `wiki_profiles` table ordering by the `updated_at` field
* See https://api.laravel.com/docs/10.x//Illuminate/Database/Query/Builder.html#method_leftJoinWhere and https://github.com/laravel/framework/discussions/52650
- Q: do we add the `purpose = data_hub AND lifespan = permanent AND audience = wide` logic to the DB query or the Laravel Model?
Note the difference between `Model::where()` and `Model::query()->where()` is described here: https://laravel-news.com/effective-eloquent#:~:text=perspective%2E-,To,query%2E