openapi: 3.1.0
info:
  title: Comunidesk API — Plusvalía (histórico)
  version: 1.0.0
  description: Snapshots periódicos del índice de plusvalía.
servers:
  - url: "https://gateway.comunidesk.com"
    description: Gateway producción
tags:
  - name: plusvalia-snapshots
    description: Plusvalía (histórico) — Snapshots periódicos del índice de plusvalía.
paths:
  /v1/rest/PlusvaliaSnapshots:
    get:
      tags:
        - plusvalia-snapshots
      operationId: listPlusvaliaSnapshot
      summary: Listar Plusvalía (histórico)
      description: Snapshots periódicos del índice de plusvalía.
      security:
        - OAuth2App: []
          ComunideskUser: []
      parameters:
        - name: edificioId
          in: query
          required: false
          schema:
            type: string
          description: Contexto de edificio (requerido en la mayoría de módulos).
        - name: $filter
          in: query
          required: false
          schema:
            type: string
          description: "Filtro OData, p.ej. edificioId eq 'abc'"
        - name: $top
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 200
        - name: $skip
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/PlusvaliaSnapshot"
                  count:
                    type: integer
        401:
          description: Token inválido
        403:
          description: Sin permiso
    post:
      tags:
        - plusvalia-snapshots
      operationId: createPlusvaliaSnapshot
      summary: Crear Plusvalía (histórico)
      security:
        - OAuth2App: []
          ComunideskUser: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PlusvaliaSnapshot"
      responses:
        200:
          description: Creado
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PlusvaliaSnapshot"
        403:
          description: Sin permiso
        422:
          description: Contrato inválido
  /v1/rest/PlusvaliaSnapshots/{id}:
    get:
      tags:
        - plusvalia-snapshots
      operationId: getPlusvaliaSnapshot
      summary: Obtener Plusvalía (histórico)
      security:
        - OAuth2App: []
          ComunideskUser: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
        - name: edificioId
          in: query
          required: false
          schema:
            type: string
          description: Contexto de edificio (requerido en la mayoría de módulos).
        - name: $filter
          in: query
          required: false
          schema:
            type: string
          description: "Filtro OData, p.ej. edificioId eq 'abc'"
        - name: $top
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 200
        - name: $skip
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: "#/components/schemas/PlusvaliaSnapshot"
        404:
          description: No encontrado
    patch:
      tags:
        - plusvalia-snapshots
      operationId: updatePlusvaliaSnapshot
      summary: Actualizar Plusvalía (histórico)
      security:
        - OAuth2App: []
          ComunideskUser: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PlusvaliaSnapshot"
      responses:
        200:
          description: Actualizado
        403:
          description: Sin permiso
        422:
          description: Contrato inválido
    delete:
      tags:
        - plusvalia-snapshots
      operationId: deletePlusvaliaSnapshot
      summary: Eliminar Plusvalía (histórico)
      security:
        - OAuth2App: []
          ComunideskUser: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
        - name: edificioId
          in: query
          required: false
          schema:
            type: string
      responses:
        200:
          description: Eliminado
        403:
          description: Sin permiso
        404:
          description: No encontrado
components:
  securitySchemes:
    OAuth2App:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Access token OAuth2 de tu aplicación.
    ComunideskUser:
      type: apiKey
      in: header
      name: x-comunidesk-user-authorization
      description: "Bearer <JWT de la cuenta Comunidesk del usuario>."
  schemas:
    PlusvaliaSnapshot:
      type: object
      description: Snapshots periódicos del índice de plusvalía.
      properties:
        _id:
          type: string
        _rev:
          type: string
        type:
          type: string
          const: plusvalia_snapshot
        edificioId:
          type: string
        periodo:
          type: string
        fecha:
          type: string
        indicePromedio:
          type: number
        config:
          type: object
          additionalProperties: true
        detalle:
          type: object
          additionalProperties: true
        createdAt:
          type: string
          readOnly: true
        updatedAt:
          type: string
          readOnly: true
      required:
        - edificioId
        - periodo
        - fecha
    OAuthScopes:
      type: string
      enum:
        - "comunidesk:read"
        - "comunidesk:write"
        - "files:pdf"
        - "files:excel"
        - "ai:models"
        - "ai:chat"
        - "ai:extract"
        - "ai:web"
        - "flex-pro:manage"
        - "flex-pro:runtime"
        - "flex-pro:marketplace"
      description: Scopes OAuth soportados por el gateway.
security:
  - OAuth2App: []
    ComunideskUser: []