{
  "openapi": "3.0.1",
  "info": {
    "title": "ArCar - API para Agencias",
    "description": "API REST para que las agencias publiquen y administren su catálogo de vehículos en ArCar. Requiere plan Profesional o Premium activo. Autenticación mediante header X-Api-Key.",
    "contact": {
      "name": "ArCar",
      "url": "https://www.arcar.org/agencias"
    },
    "version": "v1"
  },
  "paths": {
    "/rapi/v1/agencias/me": {
      "get": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Datos de la agencia autenticada, plan y cupos disponibles.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgenciaMeResponse"
                }
              }
            }
          }
        }
      }
    },
    "/rapi/v1/agencias/vehiculos": {
      "get": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Lista paginada de vehículos de la agencia.",
        "parameters": [
          {
            "name": "estado",
            "in": "query",
            "description": "Filtro opcional: pendiente, publicado, pausado.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "referenciaExterna",
            "in": "query",
            "description": "Filtro opcional por referencia externa exacta.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "description": "Página (desde 1).",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "description": "Tamaño de página (1-100).",
            "schema": {
              "type": "integer",
              "format": "int32",
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiculoApiResponsePagedResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Publica un vehículo. Si se envía `referenciaExterna` y ya existe un vehículo con esa referencia,\r\nse actualiza en lugar de duplicarse (upsert).",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VehiculoApiRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/VehiculoApiRequest"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/VehiculoApiRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiculoApiResponse"
                }
              }
            }
          },
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiculoApiResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationProblemDetails"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/rapi/v1/agencias/vehiculos/{id}": {
      "get": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Obtiene un vehículo de la agencia.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiculoApiResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Actualiza un vehículo. Si se envía `fotos`, reemplaza todas las fotos existentes.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VehiculoApiRequest"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/VehiculoApiRequest"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/VehiculoApiRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiculoApiResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Elimina (baja lógica) un vehículo.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "No Content"
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/rapi/v1/agencias/vehiculos/{id}/pausar": {
      "post": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Pausa un vehículo (deja de mostrarse en el sitio, no consume cupo).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiculoApiResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/rapi/v1/agencias/vehiculos/{id}/reactivar": {
      "post": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Reactiva un vehículo pausado. Verifica el cupo del plan.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiculoApiResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    },
    "/rapi/v1/agencias/vehiculos/{id}/destacar": {
      "post": {
        "tags": [
          "AgenciasApi"
        ],
        "summary": "Destaca un vehículo consumiendo un cupo mensual del plan.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiculoApiResponse"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AgenciaMeResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int32"
          },
          "nombre": {
            "type": "string",
            "nullable": true
          },
          "slug": {
            "type": "string",
            "nullable": true
          },
          "email": {
            "type": "string",
            "nullable": true
          },
          "plan": {
            "type": "string",
            "nullable": true
          },
          "planActivo": {
            "type": "boolean"
          },
          "feVencimientoPlan": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "limiteVehiculos": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "vehiculosPublicados": {
            "type": "integer",
            "format": "int32"
          },
          "vehiculosDisponibles": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "destacadosDisponibles": {
            "type": "integer",
            "format": "int32"
          },
          "apiKeyPrefix": {
            "type": "string",
            "nullable": true
          },
          "feApiKeyUltimoUso": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "ProblemDetails": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "instance": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": { }
      },
      "ValidationProblemDetails": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "instance": {
            "type": "string",
            "nullable": true
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "nullable": true
          }
        },
        "additionalProperties": { }
      },
      "VehiculoApiRequest": {
        "required": [
          "descripcion",
          "marca",
          "modelo"
        ],
        "type": "object",
        "properties": {
          "marca": {
            "maxLength": 100,
            "minLength": 0,
            "type": "string",
            "description": "Marca del vehículo. Ej: \"Ford\"."
          },
          "modelo": {
            "maxLength": 100,
            "minLength": 0,
            "type": "string",
            "description": "Modelo del vehículo. Ej: \"Falcon Sprint 1978\"."
          },
          "titulo": {
            "maxLength": 200,
            "minLength": 0,
            "type": "string",
            "description": "Título comercial opcional (máx. 200).",
            "nullable": true
          },
          "tipo": {
            "pattern": "^(?i)(A|N|M|auto|moto|normal)$",
            "type": "string",
            "description": "Tipo: \"A\" auto antiguo/clásico (default), \"N\" auto moderno, \"M\" moto.",
            "nullable": true
          },
          "precio": {
            "maximum": 9999999,
            "minimum": 0,
            "type": "number",
            "description": "Precio (entero, sin decimales). Máximo 7 dígitos.",
            "format": "double",
            "nullable": true
          },
          "moneda": {
            "pattern": "^(?i)(USD|ARS)$",
            "type": "string",
            "description": "Moneda ISO: \"USD\" o \"ARS\". Default \"USD\".",
            "nullable": true
          },
          "descripcion": {
            "maxLength": 8000,
            "minLength": 0,
            "type": "string",
            "description": "Descripción / características (texto libre)."
          },
          "video": {
            "maxLength": 200,
            "minLength": 0,
            "type": "string",
            "description": "URL de video (YouTube) opcional.",
            "format": "uri",
            "nullable": true
          },
          "paisIso": {
            "maxLength": 2,
            "minLength": 2,
            "type": "string",
            "description": "Código ISO de país (2 letras). Default \"AR\".",
            "nullable": true
          },
          "provincia": {
            "maxLength": 100,
            "minLength": 0,
            "type": "string",
            "description": "Nombre de la provincia tal como figura en ArCar. Ej: \"Buenos Aires\".",
            "nullable": true
          },
          "patente": {
            "maxLength": 10,
            "minLength": 0,
            "type": "string",
            "description": "Patente/dominio (opcional, no se publica).",
            "nullable": true
          },
          "referenciaExterna": {
            "maxLength": 50,
            "minLength": 0,
            "type": "string",
            "description": "Identificador del vehículo en el sistema de la agencia. Permite idempotencia y upsert.",
            "nullable": true
          },
          "fotos": {
            "maxItems": 12,
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "URLs públicas de fotos (http/https). Máximo 12. En PUT, si se envía, reemplaza todas las fotos.",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Datos de un vehículo a publicar/actualizar desde la API de agencias."
      },
      "VehiculoApiResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int32"
          },
          "referenciaExterna": {
            "type": "string",
            "nullable": true
          },
          "marca": {
            "type": "string",
            "nullable": true
          },
          "modelo": {
            "type": "string",
            "nullable": true
          },
          "titulo": {
            "type": "string",
            "nullable": true
          },
          "tipo": {
            "type": "string",
            "nullable": true
          },
          "precio": {
            "type": "number",
            "format": "double",
            "nullable": true
          },
          "moneda": {
            "type": "string",
            "nullable": true
          },
          "descripcion": {
            "type": "string",
            "nullable": true
          },
          "video": {
            "type": "string",
            "nullable": true
          },
          "pais": {
            "type": "string",
            "nullable": true
          },
          "paisIso": {
            "type": "string",
            "nullable": true
          },
          "provincia": {
            "type": "string",
            "nullable": true
          },
          "patente": {
            "type": "string",
            "nullable": true
          },
          "estado": {
            "type": "string",
            "description": "Estado: \"pendiente\" (0), \"publicado\" (2), \"pausado\" (8).",
            "nullable": true
          },
          "destacado": {
            "type": "boolean"
          },
          "nuFotos": {
            "type": "integer",
            "format": "int32"
          },
          "visitas": {
            "type": "integer",
            "format": "int32"
          },
          "url": {
            "type": "string",
            "description": "URL pública del aviso en ArCar.",
            "nullable": true
          },
          "feAlta": {
            "type": "string",
            "format": "date-time"
          },
          "advertencias": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Advertencias no bloqueantes (ej. fotos que no se pudieron descargar).",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "VehiculoApiResponsePagedResponse": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VehiculoApiResponse"
            },
            "nullable": true
          },
          "page": {
            "type": "integer",
            "format": "int32"
          },
          "pageSize": {
            "type": "integer",
            "format": "int32"
          },
          "total": {
            "type": "integer",
            "format": "int32"
          },
          "totalPages": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          }
        },
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "description": "API key de la agencia (se genera desde el panel de agencias).",
        "name": "X-Api-Key",
        "in": "header"
      }
    }
  },
  "security": [
    {
      "ApiKey": [ ]
    }
  ],
  "tags": [
    {
      "name": "AgenciasApi",
      "description": "API REST para agencias (v1). Autenticación mediante header `X-Api-Key`.\r\nDisponible para agencias con plan Profesional o Premium activo."
    }
  ]
}