openapi: 3.0.3
info:
  title: Urbido V1 API
  version: "1.0"
  description: |
    Jednoduché API s tokenovou autentizací. Token lze předat:
    - jako query param `?token=...`
    - nebo v HTTP hlavičce `Authorization: Bearer <token>`

servers:
  - url: https://vut.urbido.cz/api/v1
    description: Produkce

paths:
  /get-campuses:
    get:
      summary: Seznam areálů
      description: Vrací seznam areálů (`ubd_campuses`) smazaných = 0
      security:
        - BearerAuth: [ ]
        - QueryToken: [ ]
      parameters:
        - in: query
          name: token
          required: false
          schema:
            type: string
          description: Alternativní způsob předání tokenu (místo Bearer)
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeOk'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /get-buildings:
    get:
      summary: Seznam budov
      description: Vrací seznam budov (`ubd_buildings`) smazaných = 0
      security:
        - BearerAuth: []
        - QueryToken: []
      parameters:
        - in: query
          name: token
          required: false
          schema:
            type: string
          description: Alternativní způsob předání tokenu (místo Bearer)
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeOk'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /get-rooms:
    get:
      summary: Seznam místností
      description: Vrací seznam místností (`ubd_rooms`)
      security:
        - BearerAuth: []
        - QueryToken: []
      parameters:
        - in: query
          name: token
          schema: { type: string }
          description: Alternativní způsob předání tokenu
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeOk'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /get-floors:
    get:
      summary: Seznam pater
      description: Vrací seznam pater (`ubd_floors`)
      security:
        - BearerAuth: []
        - QueryToken: []
      parameters:
        - in: query
          name: token
          schema: { type: string }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeOk'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /get-catalogs:
    get:
      summary: Katalogy notifikací
      description: Vrací typy, stavy, skupiny a parametry notifikací
      security:
        - BearerAuth: []
        - QueryToken: []
      parameters:
        - in: query
          name: token
          schema: { type: string }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeOk'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /get-contacts:
    get:
      summary: Seznam kontaktů
      description: Vrací seznam všech kontaktů (osoby, subjekty, zaměstnanci, externí dodavatelé)
      security:
        - BearerAuth: []
        - QueryToken: []
      parameters:
        - in: query
          name: token
          schema: { type: string }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeOk'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /create-notification:
    post:
      summary: Vytvoření notifikace
      description: |
        Vytvoří novou notifikaci a případně i navázané kontakty.
        Autentizace buď `?token=...` nebo `Authorization: Bearer ...`.
      security:
        - BearerAuth: []
        - QueryToken: []
      parameters:
        - in: query
          name: token
          schema: { type: string }
          description: Alternativní způsob předání tokenu
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [ data ]
              properties:
                data:
                  $ref: '#/components/schemas/CreateNotification'
            example:
              data:
                name: "Revize EPS"
                notification_type: 1
                description: "Roční revize EPS v budově HQ"
                status: 1
                contact: 123
                due_date: "2025-12-31 00:00:00"
                parameters: '{"p1093":"quantity_test","p1090":"DOI_test"}'
                contacts:
                  - { contact_id: 1, role: 196 }
                  - { contact_id: 2, role: 197 }

      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeOk'
        '400':
          description: Invalid JSON body
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeError'
        '500':
          description: Insert/DB error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeError'
  /create-contact:
    post:
      summary: Vytvoření kontaktu
      description: |
        Vytvoří nový kontakt (osobu, subjekt, zaměstnance).
        Autentizace buď `?token=...` nebo `Authorization: Bearer ...`.
      security:
        - BearerAuth: []
        - QueryToken: []
      parameters:
        - in: query
          name: token
          schema: { type: string }
          description: Alternativní způsob předání tokenu
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [ data ]
              properties:
                data:
                  $ref: '#/components/schemas/CreateContact'
            example:
              data:
                name: "Jan Novák"
                contact_type: 1
                email: "novak@email.cz"
                phone_number: "+420123456789"
                parameters: '{"p1094":"VUTIDXXX"}'

      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeOk'
        '400':
          description: Invalid JSON body
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeError'
        '500':
          description: Insert/DB error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvelopeError'

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    QueryToken:
      type: apiKey
      in: query
      name: token

  responses:
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/EnvelopeError'
          example:
            status: error
            message: Unauthorized
            info:
              version: v1
              generated_at: "2025-11-05T10:00:00+01:00"
              hint: "Use ?token=... or Authorization: Bearer <token>"

  schemas:
    EnvelopeOk:
      type: object
      required: [status, data, info]
      properties:
        status:
          type: string
          enum: [ok]
        data:
          description: Návratová data (pole/objekt/prim.)
        info:
          type: object
          properties:
            version: { type: string, example: v1 }
            generated_at: { type: string, format: date-time }
            count: { type: integer, minimum: 0 }
            resource: { type: string }
            created: { type: boolean }
            counts:
              type: object
              additionalProperties:
                type: integer
    EnvelopeError:
      type: object
      required: [status, message, info]
      properties:
        status:
          type: string
          enum: [error]
        message:
          type: string
        info:
          type: object
          additionalProperties: true
    CreateNotification:
      type: object
      required: [ name, notification_type ]
      properties:
        name:
          type: string
          example: "Revize EPS"
        notification_type:
          type: integer
          example: 1
          description: ID z cat_types
        description:
          type: string
        status:
          type: integer
          description: ID z cat_states
        contact:
          type: integer
          description: ID z contacts (kdo vytvořil)
        due_date:
          type: string
          example: "2025-12-31 00:00:00"
          description: Datum splnění (Y-m-d H:i:s)
        parameters:
          type: string
          example: '{"p1001":"value1","p1002":"value2"}'
          description: JSON string s parametry
        contacts:
          type: array
          items:
            type: object
            required: [ contact_id, role ]
            properties:
              contact_id:
                type: integer
              role:
                type: integer
    CreateNotificationRequest:
      type: object
      required: [data]
      properties:
        data:
          $ref: '#/components/schemas/CreateNotification'
      example:
        data:
          name: "Revize EPS"
          notification_type: 1
          description: "Roční revize EPS v budově HQ"
          status: 2
          contact: 123
          due_date: "2025-12-31 00:00:00"
          parameters: '{"p1001":"value1","p1002":"value2"}'
          contacts:
            - { contact_id: 123, role: 1 }
            - { contact_id: 456, role: 2 }
    CreateContact:
      type: object
      required: [ name, contact_type ]
      properties:
        name:
          type: string
          example: "Jan Novák"
        contact_type:
          type: integer
          example: 1
          description: 1 = osoba, 2 = subjekt, 3 = zaměstnanec
        phone_number:
          type: string
          description: telefonní číslo
        email:
          type: string
          description: email
        identity_number:
          type: string
          description: IČ
        room:
          type: integer
          description: ID z ubd_rooms
        parameters:
          type: string
          example: '{"p1001":"value1","p1002":"value2"}'
          description: JSON string s parametry
    CreateContactRequest:
      type: object
      required: [ data ]
      properties:
        data:
          $ref: '#/components/schemas/CreateContact'
      example:
        data:
          name: "Jan Novák"
          contact_type: 1
          email: "novak@email.cz"
          phone_number: "+420123456789"
          parameters: '{"p1094":"VUTIDXXX"}'