{
 "openapi": "3.1.0",
 "info": {
  "title": "Rikskampen X Theme 5 API - recipes",
  "version": "0.1.0",
  "description": "Theme 5 API contract proposal (API01, decision D11): recipe options versus the selection, and the persisted week assignment."
 },
 "tags": [
  {
   "name": "recipes"
  }
 ],
 "paths": {
  "/api/theme5/clients/{clientId}/weeks/{week}/days/{dayIndex}/meals/{mealType}/recipes": {
   "get": {
    "operationId": "getMealRecipes",
    "tags": [
     "recipes"
    ],
    "summary": "Get a meal's recipe options and selection",
    "description": "All recipe options of the meal (hidden ones flagged) and, separately, the assigned (selected) recipe ids, which never contain a hidden recipe. portionKcal is null and portionAvailable false when the portion cannot be computed from the ingredient data (PORTION).",
    "security": [
     {
      "coachAuth": []
     }
    ],
    "parameters": [
     {
      "$ref": "common.openapi.json#/components/parameters/ClientId"
     },
     {
      "$ref": "common.openapi.json#/components/parameters/Week"
     },
     {
      "$ref": "common.openapi.json#/components/parameters/DayIndex"
     },
     {
      "$ref": "common.openapi.json#/components/parameters/MealType"
     }
    ],
    "responses": {
     "200": {
      "description": "Success.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "additionalProperties": false,
         "required": [
          "options",
          "assignedRecipeIds",
          "revision"
         ],
         "properties": {
          "options": {
           "type": "array",
           "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
             "recipeId",
             "name",
             "category",
             "hidden",
             "portionAvailable",
             "portionKcal"
            ],
            "properties": {
             "recipeId": {
              "type": "string"
             },
             "name": {
              "type": "string"
             },
             "category": {
              "type": "string"
             },
             "hidden": {
              "type": "boolean"
             },
             "portionAvailable": {
              "type": "boolean"
             },
             "portionKcal": {
              "type": [
               "integer",
               "null"
              ],
              "minimum": 0
             }
            }
           }
          },
          "assignedRecipeIds": {
           "type": "array",
           "uniqueItems": true,
           "items": {
            "type": "string"
           }
          },
          "revision": {
           "$ref": "common.openapi.json#/components/schemas/Revision"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "common.openapi.json#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "common.openapi.json#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "common.openapi.json#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "common.openapi.json#/components/responses/NotFound"
     }
    },
    "x-theme5-rules": [
     "R-HIDDEN-NOT-ASSIGNED",
     "R-COACH-ASSIGNED"
    ]
   }
  },
  "/api/theme5/clients/{clientId}/weeks/{week}/days/{dayIndex}/meals/{mealType}/selection": {
   "put": {
    "operationId": "setMealRecipeSelection",
    "tags": [
     "recipes"
    ],
    "summary": "Hide or show recipes for one day's meal",
    "description": "Hide or show recipes for this day's meal only: a hidden recipe leaves the selection and never appears in assignedRecipeIds; other meals, other days and the recipe library are unchanged. A past day returns 409 DAY_LOCKED.",
    "security": [
     {
      "coachAuth": []
     }
    ],
    "parameters": [
     {
      "$ref": "common.openapi.json#/components/parameters/ClientId"
     },
     {
      "$ref": "common.openapi.json#/components/parameters/Week"
     },
     {
      "$ref": "common.openapi.json#/components/parameters/DayIndex"
     },
     {
      "$ref": "common.openapi.json#/components/parameters/MealType"
     },
     {
      "$ref": "common.openapi.json#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false,
        "required": [
         "expectedRevision",
         "hiddenRecipeIds"
        ],
        "properties": {
         "expectedRevision": {
          "$ref": "common.openapi.json#/components/schemas/Revision"
         },
         "hiddenRecipeIds": {
          "type": "array",
          "uniqueItems": true,
          "items": {
           "type": "string"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "additionalProperties": false,
         "required": [
          "options",
          "assignedRecipeIds",
          "revision",
          "audit"
         ],
         "properties": {
          "options": {
           "type": "array",
           "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
             "recipeId",
             "name",
             "category",
             "hidden",
             "portionAvailable",
             "portionKcal"
            ],
            "properties": {
             "recipeId": {
              "type": "string"
             },
             "name": {
              "type": "string"
             },
             "category": {
              "type": "string"
             },
             "hidden": {
              "type": "boolean"
             },
             "portionAvailable": {
              "type": "boolean"
             },
             "portionKcal": {
              "type": [
               "integer",
               "null"
              ],
              "minimum": 0
             }
            }
           }
          },
          "assignedRecipeIds": {
           "type": "array",
           "uniqueItems": true,
           "items": {
            "type": "string"
           }
          },
          "revision": {
           "$ref": "common.openapi.json#/components/schemas/Revision"
          },
          "audit": {
           "$ref": "common.openapi.json#/components/schemas/AuditStamp"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "common.openapi.json#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "common.openapi.json#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "common.openapi.json#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "common.openapi.json#/components/responses/NotFound"
     },
     "409": {
      "$ref": "common.openapi.json#/components/responses/Conflict"
     },
     "422": {
      "$ref": "common.openapi.json#/components/responses/Unprocessable"
     }
    },
    "x-theme5-rules": [
     "R-HIDDEN-NOT-ASSIGNED",
     "R-SELECTION-SCOPED",
     "R-PAST-DAY-LOCKED",
     "R-STALE-REVISION",
     "R-IDEMPOTENT-WRITE",
     "R-AUDITED-WRITE",
     "R-COACH-ASSIGNED",
     "R-SCHEMA-400"
    ]
   }
  },
  "/api/theme5/clients/{clientId}/weeks/{week}/assignment": {
   "get": {
    "operationId": "getWeekAssignment",
    "tags": [
     "recipes"
    ],
    "summary": "Get the persisted week assignment",
    "description": "The persisted week assignment: the selected recipeIds per meal and day; a hidden recipe is never included (R04, API_CONTRACT 3.1).",
    "security": [
     {
      "coachAuth": []
     }
    ],
    "parameters": [
     {
      "$ref": "common.openapi.json#/components/parameters/ClientId"
     },
     {
      "$ref": "common.openapi.json#/components/parameters/Week"
     }
    ],
    "responses": {
     "200": {
      "description": "Success.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "additionalProperties": false,
         "required": [
          "clientId",
          "week",
          "days",
          "revision"
         ],
         "properties": {
          "clientId": {
           "type": "string"
          },
          "week": {
           "type": "integer",
           "minimum": 1,
           "maximum": 52
          },
          "days": {
           "type": "array",
           "maxItems": 7,
           "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
             "dayIndex",
             "meals"
            ],
            "properties": {
             "dayIndex": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
             },
             "meals": {
              "type": "array",
              "maxItems": 5,
              "items": {
               "type": "object",
               "additionalProperties": false,
               "required": [
                "mealType",
                "recipeIds"
               ],
               "properties": {
                "mealType": {
                 "$ref": "common.openapi.json#/components/schemas/MealType"
                },
                "recipeIds": {
                 "type": "array",
                 "uniqueItems": true,
                 "items": {
                  "type": "string"
                 }
                }
               }
              }
             }
            }
           }
          },
          "revision": {
           "$ref": "common.openapi.json#/components/schemas/Revision"
          }
         }
        }
       }
      }
     },
     "400": {
      "$ref": "common.openapi.json#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "common.openapi.json#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "common.openapi.json#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "common.openapi.json#/components/responses/NotFound"
     }
    },
    "x-theme5-rules": [
     "R-HIDDEN-NOT-ASSIGNED",
     "R-COACH-ASSIGNED"
    ]
   }
  }
 },
 "components": {
  "securitySchemes": {
   "coachAuth": {
    "$ref": "common.openapi.json#/components/securitySchemes/coachAuth"
   }
  }
 }
}
