{
 "openapi": "3.1.0",
 "info": {
  "title": "Dino-Sore API",
  "version": "0.60.0",
  "description": "Workout log API. Human/AI guide with data formats and examples: /llms.txt. Test version: data may become distorted or lost."
 },
 "servers": [
  {
   "url": "/"
  }
 ],
 "tags": [
  {
   "name": "user",
   "description": "Logged-in user's own data (cookie tk_session)"
  },
  {
   "name": "admin",
   "description": "Owner only. Requires Authorization: Bearer ADMIN_TOKEN. Disabled (404) when the server has no ADMIN_TOKEN."
  },
  {
   "name": "agent",
   "description": "Personal API key (Bearer tk_...): own data only, narrow writes. Not enabled on the server by default."
  }
 ],
 "components": {
  "securitySchemes": {
   "session": {
    "type": "apiKey",
    "in": "cookie",
    "name": "tk_session",
    "description": "Set by POST /api/login. Valid 300 days since the last request, renewed on every request. Request bodies must be sent as application/json."
   },
   "admin": {
    "type": "http",
    "scheme": "bearer"
   },
   "agentKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "Personal API key (tk_...) created by the user in the app (Asetukset → Tekoälyavaimet). Only works when the server has the feature enabled. Allows only GET /api/me, GET /api/data and POST /api/agent/*. Never admin, sharing, publishing, feedback or key management."
   }
  },
  "schemas": {
   "Credentials": {
    "type": "object",
    "required": [
     "user",
     "pass"
    ],
    "properties": {
     "user": {
      "type": "string"
     },
     "pass": {
      "type": "string"
     }
    }
   },
   "Set": {
    "type": "object",
    "required": [
     "w",
     "r"
    ],
    "properties": {
     "w": {
      "type": "number",
      "description": "weight in the user's unit (settings.unit)"
     },
     "r": {
      "type": "integer",
      "description": "reps (0 for sets logged only with time or distance)"
     },
     "rpe": {
      "type": "number",
      "minimum": 1,
      "maximum": 10
     },
     "p": {
      "type": "integer",
      "description": "partial reps"
     },
     "m": {
      "const": 1,
      "description": "myo-rep mini set"
     },
     "d": {
      "const": 1,
      "description": "drop set"
     },
     "sec": {
      "type": "number",
      "description": "time in seconds (cardio, plank)"
     },
     "dist": {
      "type": "number",
      "description": "distance in metres"
     },
     "kal": {
      "type": "number",
      "description": "incline in percent (treadmill)"
     },
     "hgt": {
      "type": "number",
      "description": "height in centimetres (jumps, box height)"
     },
     "cad": {
      "type": "number",
      "description": "cadence, steps per minute (running)"
     },
     "hr": {
      "type": "number",
      "description": "average heart rate, bpm (running)"
     },
     "hrx": {
      "type": "number",
      "description": "maximum heart rate, bpm (cardio)"
     },
     "kcal": {
      "type": "number",
      "description": "calories burnt, kcal (cardio)"
     },
     "kcalE": {
      "const": 1,
      "description": "1 = kcal is an app estimate"
     }
    }
   },
   "Session": {
    "type": "object",
    "required": [
     "id",
     "date",
     "ex"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "date": {
      "type": "string",
      "format": "date-time"
     },
     "dayId": {
      "type": "string"
     },
     "dayName": {
      "type": "string"
     },
     "prog": {
      "type": "object",
      "description": "Optional. Program the workout belongs to: key k, origin o, name, week w of n, workouts per week f. Missing = standalone workout.",
      "properties": {
       "k": {
        "type": "string"
       },
       "name": {
        "type": "string"
       },
       "w": {
        "type": "integer"
       },
       "n": {
        "type": "integer"
       },
       "f": {
        "type": "integer"
       },
       "o": {
        "type": "string",
        "description": "Program origin id (program.origin or program.rid)"
       }
      }
     },
     "ex": {
      "type": "array",
      "items": {
       "type": "object",
       "required": [
        "id",
        "name",
        "sets"
       ],
       "properties": {
        "id": {
         "type": "string",
         "description": "program exercise id, or imp_<slug> for exercises not in the program"
        },
        "ex": {
         "type": "string",
         "description": "Permanent exercise id (library id or custom_<random>); optional, added by the app when missing"
        },
        "name": {
         "type": "string"
        },
        "mode": {
         "type": "string"
        },
        "result": {
         "enum": [
          "up",
          "same",
          "fail",
          "skip"
         ]
        },
        "fx": {
         "enum": [
          1,
          3
         ],
         "description": "cardio effort asked after the workout (optional): 1 = easy, 3 = hard. Missing = just right. The cardio suggestion uses it."
        },
        "sets": {
         "type": "array",
         "items": {
          "$ref": "#/components/schemas/Set"
         }
        }
       }
      }
     }
    }
   },
   "LogDoc": {
    "type": "object",
    "description": "Document log_YYYY-MM: workouts of one month",
    "properties": {
     "sessions": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/Session"
      }
     }
    }
   },
   "Exercise": {
    "type": "object",
    "required": [
     "id",
     "name",
     "mode"
    ],
    "properties": {
     "ex": {
      "type": "string",
      "description": "Permanent exercise id: a library id (e.g. bench_press, list in liikkeet.json) or custom_<random> for own exercises (name in StateDoc.customEx). Optional: the app adds it when missing and falls back to name."
     },
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "mode": {
      "enum": [
       "double",
       "volume",
       "percent",
       "rpe",
       "none"
      ]
     },
     "sets": {
      "type": "integer"
     },
     "min": {
      "type": "integer"
     },
     "max": {
      "type": "integer"
     },
     "start": {
      "type": "number"
     },
     "inc": {
      "type": "number"
     },
     "tm": {
      "type": "number",
      "description": "training max (percent mode)"
     },
     "cycle": {
      "type": "string",
      "description": "percent mode weeks, e.g. 65x5x3, 75x5x3"
     },
     "vStart": {
      "type": "integer"
     },
     "vMax": {
      "type": "integer"
     },
     "rpe": {
      "type": "number"
     },
     "tech": {
      "type": "object",
      "description": "optional set technique {t: myo|drop|superset, ...}"
     },
     "track": {
      "type": "array",
      "items": {
       "type": "string",
       "enum": [
        "w",
        "r",
        "min",
        "s",
        "km",
        "m",
        "kal",
        "cad",
        "hr",
        "hrx",
        "kcal",
        "cm",
        "in",
        "cmd"
       ]
      },
      "description": "logged fields; missing = [w, r]. min/s write sec, km/m/cmd write dist (cmd = input in cm), cm/in write hgt (cm), cad, hr, hrx and kcal write the set fields of the same name. Without both w and r the exercise has no progression (mode none)."
     }
    }
   },
   "StateDoc": {
    "type": "object",
    "description": "Document state: program, progression state, settings and saved own programs",
    "properties": {
     "customEx": {
      "type": "object",
      "description": "Own exercises: {custom_<random>: {name, eq?, f?, p?, s?, al?, del?, to?}}. Added by the app. al = former names, del = deleted (hidden, history kept), to = merged into that exercise id. Optional user-set details: eq = equipment, f = movement family (liikkeet.json family), p/s = primary/secondary muscle ids. With them the exercise appears in muscle maps and swap suggestions like a library exercise.",
      "additionalProperties": {
       "type": "object",
       "properties": {
        "name": {
         "type": "string"
        },
        "eq": {
         "type": "string",
         "enum": ["barbell", "dumbbell", "bodyweight", "other"]
        },
        "f": {
         "type": "string"
        },
        "p": {
         "type": "array",
         "items": {"type": "string"}
        },
        "s": {
         "type": "array",
         "items": {"type": "string"}
        }
       }
      }
     },
     "exv": {
      "type": "integer",
      "description": "Exercise id migration version (1 = exercises have the ex field). Set by the app."
     },
     "program": {
      "type": "object",
      "properties": {
       "name": {
        "type": "string"
       },
       "days": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "id": {
           "type": "string"
          },
          "name": {
           "type": "string"
          },
          "exercises": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Exercise"
           }
          }
         }
        }
       }
      }
     },
     "ex": {
      "type": "object",
      "additionalProperties": {
       "type": "object"
      },
      "description": "progression state per exercise id; may be empty"
     },
     "settings": {
      "type": "object",
      "properties": {
       "unit": {
        "enum": [
         "kg",
         "lb"
        ]
       },
       "lang": {
        "enum": [
         "fi",
         "en"
        ]
       },
       "exLangSep": {
        "type": "integer",
        "enum": [
         0,
         1
        ],
        "description": "1 = exercise names use exLang instead of lang. Default 0."
       },
       "exLang": {
        "enum": [
         "fi",
         "en"
        ],
        "description": "Exercise name language when exLangSep is 1. Default en."
       },
       "theme": {
        "enum": [
         "auto",
         "light",
         "dark"
        ]
       },
       "home": {
        "type": "array",
        "description": "Workout page widgets in order: [{id: next|days|goal|total|last|rm|prs|strain|targets|vol|prog|inbox|backup|month|streak|pubtop|body|tpl, on: 0|1, size: S|L, w?: width in twelfths 4..12 (6..12 for L-only widgets; missing = 6 for S, 12 for L; content uses S when w <= 6), h?: minimum height in px, opt?: widget options}]. Missing = default order.",
        "items": {"type": "object"}
       },
       "card": {
        "enum": [
         "classic",
         "full",
         "compact"
        ],
        "description": "Exercise card layout in a workout: classic (default), full (all actions, arranged) or compact (only the next set open, rest in a menu)."
       },
       "rest": {
        "type": "integer"
       },
       "round": {
        "type": "number"
       },
       "weeklyGoal": {
        "type": "integer"
       },
       "bodyGoal": {
        "type": "number"
       },
       "liftGoals": {
        "type": "object",
        "description": "Target 1RM per main lift (canonical Finnish exercise name -> weight in the user's unit)",
        "additionalProperties": {
         "type": "number"
        }
       },
       "runGoals": {
        "type": "object",
        "description": "Running goal times in seconds: k5 (5 km) and k10 (10 km)",
        "additionalProperties": {
         "type": "integer"
        }
       },
       "failLimit": {
        "type": "integer"
       },
       "deloadPct": {
        "type": "number"
       },
       "tpl": {
        "type": "object"
       },
       "backupRemind": {
        "type": "integer",
        "enum": [
         0,
         1
        ],
        "description": "backup reminder every ~6 months: 1 on (default), 0 off permanently"
       },
       "backupNext": {
        "type": "number",
        "description": "ms timestamp when the next backup reminder is due; 0 = 6 months after the first workout"
       },
       "backupSnooze": {
        "type": "number",
        "description": "ms timestamp; reminder hidden until then (× = until tomorrow)"
       },
       "colors": {
        "type": "object",
        "description": "colour scheme: pal = oletus|klassinen|neon|metsa|berserkki|oma (aurinko is accepted as an alias of oletus); custom = {treeni, suunn, hist, mitat} hex colours used when pal is oma"
       },
       "effort": {
        "enum": [
         "rpe",
         "rir"
        ],
        "description": "effort scale shown in the app; data is always stored as RPE (RIR = 10 − RPE)"
       }
      }
     },
     "myProgs": {
      "type": "array",
      "description": "Saved own programs (Omat ohjelmat). The previous own program is stored here automatically when the user switches to another program.",
      "items": {
       "type": "object",
       "properties": {
        "oid": {
         "type": "string"
        },
        "name": {
         "type": "string"
        },
        "saved": {
         "type": "integer",
         "description": "epoch ms"
        },
        "freq": {
         "type": "integer"
        },
        "program": {
         "type": "object",
         "description": "same shape as StateDoc.program"
        },
        "ex": {
         "type": "object",
         "description": "progression state per exercise id at the time of saving"
        }
       }
      }
     }
    }
   },
   "BodyDoc": {
    "type": "object",
    "description": "Document body: body weight and measurements",
    "properties": {
     "entries": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "d": {
         "type": "string",
         "format": "date"
        },
        "kg": {
         "type": "number",
         "description": "body weight in the user's unit"
        }
       }
      }
     },
     "meas": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "d": {
         "type": "string",
         "format": "date"
        },
        "v": {
         "type": "object",
         "description": "waist, hips, chest, shoulders, arm, forearm, thigh, calf, neck (cm), fat (%)",
         "additionalProperties": {
          "type": "number"
         }
        }
       }
      }
     }
    }
   },
   "Docs": {
    "type": "object",
    "properties": {
     "docs": {
      "type": "object",
      "description": "keys: state, body, log_YYYY-MM",
      "properties": {
       "state": {
        "$ref": "#/components/schemas/StateDoc"
       },
       "body": {
        "$ref": "#/components/schemas/BodyDoc"
       }
      },
      "patternProperties": {
       "^log_\\d{4}-\\d{2}$": {
        "$ref": "#/components/schemas/LogDoc"
       }
      }
     }
    }
   }
  }
 },
 "paths": {
  "/api/login": {
   "post": {
    "tags": [
     "user"
    ],
    "summary": "Log in (sets cookie tk_session)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/Credentials"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "{user}"
     },
     "401": {
      "description": "invalid_credentials"
     },
     "429": {
      "description": "too_many_attempts"
     }
    }
   }
  },
  "/api/logout": {
   "post": {
    "tags": [
     "user"
    ],
    "summary": "Log out",
    "responses": {
     "200": {
      "description": "ok"
     }
    }
   }
  },
  "/api/password": {
   "post": {
    "tags": ["user"],
    "security": [{"session": []}],
    "summary": "Change own password (needs the current one; other sessions are logged out)",
    "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["old", "pass"], "properties": {"old": {"type": "string"}, "pass": {"type": "string", "minLength": 3}}}}}},
    "responses": {
     "200": {"description": "{ok: true}"},
     "400": {"description": "bad_pass: new password too short"},
     "401": {"description": "invalid_credentials: current password wrong"},
     "429": {"description": "too_many_attempts (10 / 15 min)"}
    }
   }
  },
  "/api/me": {
   "get": {
    "tags": [
     "user"
    ],
    "summary": "Current user ({user: null} when not logged in)",
    "responses": {
     "200": {
      "description": "{user, id}: user = unique login name (an admin can rename it), id = permanent account id"
     }
    }
   }
  },
  "/api/data": {
   "get": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "All documents of the user",
    "responses": {
     "200": {
      "description": "documents",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Docs"
        }
       }
      }
     },
     "401": {
      "description": "not_logged_in"
     }
    }
   }
  },
  "/api/data/{key}": {
   "put": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Replace one whole document (GET, modify, PUT back)",
    "parameters": [
     {
      "name": "key",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^(state|progs|body|log_\\d{4}-\\d{2})$"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "oneOf": [
         {
          "$ref": "#/components/schemas/StateDoc"
         },
         {
          "$ref": "#/components/schemas/BodyDoc"
         },
         {
          "$ref": "#/components/schemas/LogDoc"
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "ok"
     },
     "400": {
      "description": "bad_key or bad_json"
     },
     "401": {
      "description": "not_logged_in"
     },
     "413": {
      "description": "too_large (max 1 MB)"
     }
    }
   }
  },
  "/api/admin/users": {
   "get": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "List users",
    "responses": {
     "200": {
      "description": "{users}"
     },
     "403": {
      "description": "wrong token"
     }
    }
   },
   "post": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "Create a user or reset a password",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/Credentials"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "{ok, user, created}"
     },
     "400": {
      "description": "bad_user or bad_pass"
     }
    }
   }
  },
  "/api/admin/settings-stats": {
   "get": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "Anonymous settings summary: counts per setting value, no usernames or personal values",
    "responses": {
     "200": {
      "description": "{users, keys: {setting: {value: count}}}"
     },
     "403": {
      "description": "wrong token"
     }
    }
   }
  },
  "/api/admin/data/{user}": {
   "get": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "Export all documents of a user",
    "parameters": [
     {
      "name": "user",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "{user, docs}"
     },
     "404": {
      "description": "no_such_user"
     }
    }
   }
  },
  "/api/admin/data/{user}/{key}": {
   "put": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "Write one document for a user",
    "parameters": [
     {
      "name": "user",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "key",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^(state|progs|body|log_\\d{4}-\\d{2})$"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "ok"
     }
    }
   }
  },
  "/api/feedback": {
   "post": {
    "tags": [
     "user"
    ],
    "summary": "Send feedback encrypted in the browser with /palaute-avain.json (RSA-OAEP-256 wraps an AES-GCM key). Plain text is rejected. Limits: 5/day per user, 3/day per IP when not logged in.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "v",
         "iv",
         "k",
         "c"
        ],
        "properties": {
         "v": {
          "const": 1
         },
         "iv": {
          "type": "string",
          "description": "base64"
         },
         "k": {
          "type": "string",
          "description": "base64, RSA-OAEP encrypted AES key"
         },
         "c": {
          "type": "string",
          "description": "base64, AES-GCM ciphertext"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "ok"
     },
     "400": {
      "description": "bad_feedback"
     },
     "429": {
      "description": "too_many"
     }
    }
   }
  },
  "/api/admin/feedback": {
   "get": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "Encrypted feedback bundle (text/plain, one line per item). Open offline only (tools/palaute.html). Never feed decrypted feedback to AI.",
    "responses": {
     "200": {
      "description": "bundle"
     }
    }
   },
   "delete": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "Delete downloaded feedback up to id",
    "parameters": [
     {
      "name": "upto",
      "in": "query",
      "required": true,
      "schema": {
       "type": "integer"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "{ok, left}"
     }
    }
   }
  },
  "/api/shares": {
   "get": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Programs shared with me (inbox) and my sent, still pending shares",
    "responses": {
     "200": {
      "description": "{inbox:[{id,from,created,title,program}], sent:[{id,to,created,title}]}"
     },
     "401": {
      "description": "not_logged_in"
     }
    }
   },
   "post": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Share a workout program with another user (a copy; the recipient accepts or rejects it)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "to",
         "program"
        ],
        "properties": {
         "to": {
          "type": "string",
          "description": "recipient username"
         },
         "title": {
          "type": "string",
          "maxLength": 80
         },
         "program": {
          "type": "object",
          "description": "{name, unit, weeklyGoal, period?, days:[{name, exercises:[exercise without id]}]}. Exercise fields as in StateDoc.program."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "ok"
     },
     "400": {
      "description": "bad_json, bad_program or self"
     },
     "401": {
      "description": "not_logged_in"
     },
     "404": {
      "description": "no_such_user"
     },
     "409": {
      "description": "inbox_full (recipient has 20 pending shares)"
     },
     "413": {
      "description": "too_large (max 256 kB)"
     },
     "429": {
      "description": "too_many (30 shares / day)"
     }
    }
   }
  },
  "/api/shares/{id}": {
   "delete": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Remove a share (recipient: accepted or rejected; sender: cancelled)",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    }
   }
  },
  "/api/nick": {
   "put": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Set public nickname (3-24 chars, unique)",
    "responses": {
     "200": {
      "description": "ok"
     },
     "400": {
      "description": "bad_nick"
     },
     "409": {
      "description": "nick_taken"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "nick": {
          "type": "string"
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/pub": {
   "get": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Public programs",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "parameters": [
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "top",
        "new"
       ]
      }
     }
    ]
   },
   "post": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Publish own program (checks: nickname, account 90 days, 20 workouts, program completed, thumbs from 2 friends it was shared with, max 3)",
    "responses": {
     "200": {
      "description": "ok, returns id"
     },
     "403": {
      "description": "checks_failed (with checks)"
     },
     "409": {
      "description": "already_published"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "origin": {
          "type": "string"
         },
         "level": {
          "type": "string",
          "enum": [
           "Aloittelija",
           "Keskitaso",
           "Kokenut"
          ]
         },
         "program": {
          "type": "object"
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/pub/register": {
   "post": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Register an own program origin (first registrant becomes owner)",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "origin": {
          "type": "string"
         },
         "program": {
          "type": "object"
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/pub/status": {
   "get": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Thumbs, thumb eligibility, publication and owner's publish checks for an origin",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "parameters": [
     {
      "name": "origin",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/api/pub/{id}": {
   "get": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "One public program with its program",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     }
    ]
   },
   "delete": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Unpublish (author)",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     }
    ]
   }
  },
  "/api/pub/{id}/report": {
   "post": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Report a public program (3 reports hide it, 5 / day)",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "reason": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     }
    ]
   }
  },
  "/api/thumbs": {
   "post": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Thumb up a program origin (after one training week, or one cycle for percentage programs; not own; 10 / day)",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "origin": {
          "type": "string"
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/thumbs/{origin}": {
   "delete": {
    "tags": [
     "user"
    ],
    "security": [
     {
      "session": []
     }
    ],
    "summary": "Remove my thumb",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "parameters": [
     {
      "name": "origin",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/api/admin/pub": {
   "get": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "All publications with reports",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    }
   }
  },
  "/api/admin/pub/{id}": {
   "post": {
    "tags": [
     "admin"
    ],
    "security": [
     {
      "admin": []
     }
    ],
    "summary": "Set publication status",
    "responses": {
     "200": {
      "description": "ok"
     },
     "401": {
      "description": "not_logged_in"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "status": {
          "type": "string",
          "enum": [
           "public",
           "hidden",
           "removed"
          ]
         }
        }
       }
      }
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     }
    ]
   }
  },
  "/api/agent/session": {
   "post": {
    "tags": [
     "agent"
    ],
    "security": [
     {
      "agentKey": []
     }
    ],
    "summary": "Add one workout to the right month document (key log_YYYY-MM). The same id twice does not create a duplicate.",
    "parameters": [
     {
      "name": "dry",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "1"
       ]
      },
      "description": "1 = validate only, store nothing"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "id",
         "date",
         "ex"
        ],
        "properties": {
         "id": {
          "type": "string",
          "description": "your own unique id, 1-40 chars [A-Za-z0-9_-]; idempotency key"
         },
         "date": {
          "type": "string",
          "format": "date-time"
         },
         "dayId": {
          "type": "string"
         },
         "dayName": {
          "type": "string"
         },
         "start": {
          "type": "string",
          "format": "date-time"
         },
         "dur": {
          "type": "number",
          "description": "seconds"
         },
         "ex": {
          "type": "array",
          "items": {
           "type": "object",
           "required": [
            "name",
            "sets"
           ],
           "properties": {
            "name": {
             "type": "string"
            },
            "ex": {
             "type": "string",
             "description": "library id, e.g. bench_press"
            },
            "id": {
             "type": "string"
            },
            "mode": {
             "type": "string",
             "enum": [
              "double",
              "volume",
              "percent",
              "rpe",
              "none"
             ]
            },
            "result": {
             "type": "string",
             "enum": [
              "up",
              "same",
              "fail",
              "skip"
             ]
            },
            "sets": {
             "type": "array",
             "items": {
              "type": "object",
              "properties": {
               "id": {
                "type": "string"
               },
               "w": {
                "type": "number"
               },
               "r": {
                "type": "number"
               },
               "rpe": {
                "type": "number",
                "minimum": 0,
                "maximum": 10.5
               },
               "p": {
                "type": "number"
               },
               "t": {
                "type": "string",
                "format": "date-time"
               },
               "m": {
                "const": 1
               },
               "d": {
                "const": 1
               },
               "sec": {
                "type": "number"
               },
               "dist": {
                "type": "number"
               },
               "kal": {
                "type": "number"
               },
               "hgt": {
                "type": "number"
               }
              }
             }
            }
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "{ok:true, duplicate:bool, key}"
     },
     "400": {
      "description": "bad_request: {errors:[...]} (nothing stored)"
     },
     "401": {
      "description": "invalid_key"
     },
     "403": {
      "description": "not_allowed_for_key"
     },
     "413": {
      "description": "too_large"
     },
     "429": {
      "description": "too_many: rate limit (120 requests/hour, 200 writes/day, 20 settings changes/day per key)"
     }
    }
   }
  },
  "/api/agent/body": {
   "post": {
    "tags": [
     "agent"
    ],
    "security": [
     {
      "agentKey": []
     }
    ],
    "summary": "Add or update one day's body weight and/or measurements (merged into the body document; other days untouched).",
    "parameters": [
     {
      "name": "dry",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "1"
       ]
      },
      "description": "1 = validate only, store nothing"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "date"
        ],
        "properties": {
         "date": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
         },
         "kg": {
          "type": "number",
          "description": "in the user's unit"
         },
         "meas": {
          "type": "object",
          "description": "waist, hips, chest, shoulders, arm, forearm, thigh, calf, neck (cm), fat (%)",
          "additionalProperties": {
           "type": "number"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "{ok:true}"
     },
     "400": {
      "description": "bad_request: {errors:[...]} (nothing stored)"
     },
     "401": {
      "description": "invalid_key"
     },
     "403": {
      "description": "not_allowed_for_key"
     },
     "413": {
      "description": "too_large"
     },
     "429": {
      "description": "too_many: rate limit (120 requests/hour, 200 writes/day, 20 settings changes/day per key)"
     }
    }
   }
  },
  "/api/agent/settings": {
   "post": {
    "tags": [
     "agent"
    ],
    "security": [
     {
      "agentKey": []
     }
    ],
    "summary": "Merge allowed settings into state.settings. A backup of the state is saved first (the user can restore it in the app). unit cannot be changed. liftGoals and runGoals are merged per key (null removes a key).",
    "parameters": [
     {
      "name": "dry",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "1"
       ]
      },
      "description": "1 = validate only, store nothing"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "description": "Allowed keys: trackAll, exLangSep, wakeLock, backupRemind, flaskBtn, rewardText, sliderOn, stpOn, lockOrder, tabSwipe, undoSwipe, restAuto, tickClock, restBuzz, motion, haptic, weekStart (0|1); sex, exLang, effort, effortField, notify, lang, theme, card, keepField (0|1|2), restAdd (15|30|60), holdMs (400|700|1000) (enums); height, rest, failLimit, deloadPct, round, weeklyGoal, repsLeft, fontPct, uiPct, bodyGoal, myoRest (numbers in range); liftGoals, runGoals, tags, colors. Errors list the allowed keys.",
        "additionalProperties": true
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "{ok:true, settings}"
     },
     "400": {
      "description": "bad_request: {errors:[...]} (nothing stored)"
     },
     "401": {
      "description": "invalid_key"
     },
     "403": {
      "description": "not_allowed_for_key"
     },
     "413": {
      "description": "too_large"
     },
     "429": {
      "description": "too_many: rate limit (120 requests/hour, 200 writes/day, 20 settings changes/day per key)"
     }
    }
   }
  }
 }
}
