openapi: 3.0.3
info:
  title: Site Management API
  version: 1.0.0
  description: API for managing sites and notes in a user-authenticated environment.

paths:
  /sites:
    get:
      summary: Get list of sites
      operationId: getSites
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Site"
    post:
      summary: Create a new site
      operationId: createSite
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                site_path:
                  type: string
                name:
                  type: string
              required:
                - site_path
                - name
      responses:
        "201":
          description: Site created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Site"
        "400":
          description: Site already exists or validation error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /sites/{site_path}:
    get:
      summary: Get a site by path
      operationId: getSite
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site to retrieve
      responses:
        "200":
          description: Site found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SiteDetail"
        "404":
          description: Site not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    put:
      summary: Update a site
      operationId: updateSite
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site to update
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                site_path:
                  type: string
                name:
                  type: string
                headline:
                  type: string
                about:
                  type: string
                domain:
                  type: string
              required:
                - site_path
      responses:
        "200":
          description: Site updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Site"
        "400":
          description: Error in updating site
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    delete:
      summary: Delete a site
      operationId: deleteSite
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site to delete
      responses:
        "200":
          description: Site deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        "404":
          description: Site not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /sites/{site_path}/notes:
    get:
      summary: Get notes for a site
      operationId: getNotesForSite
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
      responses:
        "200":
          description: Notes found
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Note"
        "404":
          description: Site or notes not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    post:
      summary: Create a note for a site
      operationId: createNoteForSite
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                body:
                  type: string
                visibility:
                  type: string
              required:
                - body
      responses:
        "201":
          description: Note created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Note"
        "400":
          description: Error in creating note
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /sites/{site_path}/notes/{note_path}:
    get:
      summary: Get a note by path
      operationId: getNote
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
        - in: path
          name: note_path
          schema:
            type: string
          required: true
          description: The path of the note to retrieve
      responses:
        "200":
          description: Note found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/NoteDetail"
        "404":
          description: Note not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    put:
      summary: Update a note
      operationId: updateNote
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
        - in: path
          name: note_path
          schema:
            type: string
          required: true
          description: The path of the note to update
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                body:
                  type: string
                visibility:
                  type: string
              required:
                - body
      responses:
        "200":
          description: Note updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Note"
        "400":
          description: Error in updating note
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    delete:
      summary: Delete a note
      operationId: deleteNote
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
        - in: path
          name: note_path
          schema:
            type: string
          required: true
          description: The path of the note to delete
      responses:
        "200":
          description: Note deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        "404":
          description: Note not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /sites/{site_path}/notes/{note_path}/links:
    get:
      summary: Get all links from a note
      operationId: getLinksFromNote
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
        - in: path
          name: note_path
          schema:
            type: string
          required: true
          description: The path of the note to get links from
      responses:
        "200":
          description: Links found
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
        "404":
          description: Note not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /sites/{site_path}/notes/{note_path}/body:
    get:
      summary: Get the body of a note as HTML
      operationId: getNoteBodyAsHTML
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
        - in: path
          name: note_path
          schema:
            type: string
          required: true
          description: The path of the note to retrieve the body for
      responses:
        "200":
          description: Note body found
          content:
            application/json:
              schema:
                type: object
                properties:
                  body:
                    type: string
        "404":
          description: Note not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /sites/{site_path}/notes/{note_path}.md:
    get:
      summary: Get the note in Markdown format
      operationId: getNoteAsMarkdown
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
        - in: path
          name: note_path
          schema:
            type: string
          required: true
          description: The path of the note to retrieve in Markdown format
      responses:
        "200":
          description: Note found in Markdown format
          content:
            text/plain:
              schema:
                type: string
        "404":
          description: Note not found
          content:
            text/plain:
              schema:
                type: string
                example: Note not found

  /sites/{site_path}/notes/{note_path}.txt:
    get:
      summary: Get the note in plain text format
      operationId: getNoteAsPlainText
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
        - in: path
          name: note_path
          schema:
            type: string
          required: true
          description: The path of the note to retrieve in plain text format
      responses:
        "200":
          description: Note found in plain text format
          content:
            text/plain:
              schema:
                type: string
        "404":
          description: Note not found
          content:
            text/plain:
              schema:
                type: string
                example: Note not found

  /sites/{site_path}/notes/search:
    get:
      summary: Search notes within a site
      operationId: searchNotes
      parameters:
        - in: path
          name: site_path
          schema:
            type: string
          required: true
          description: The path of the site
        - in: query
          name: term
          schema:
            type: string
          required: true
          description: The search term
        - in: query
          name: mode
          schema:
            type: string
          required: false
          description: The search mode (exact or semantic)
      responses:
        "200":
          description: Notes found
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Note"
        "404":
          description: Site not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

components:
  schemas:
    Site:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        site_path:
          type: string
    SiteDetail:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        site_path:
          type: string
        total_notes:
          type: integer
        notes:
          type: array
          items:
            $ref: "#/components/schemas/Note"
    Note:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        body:
          type: string
        visibility:
          type: string
    NoteDetail:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        body:
          type: string
        visibility:
          type: string
        links:
          type: array
          items:
            type: string
    Error:
      type: object
      properties:
        message:
          type: string
