{
  "openapi": "3.1.0",
  "info": {
    "title": "Solaris CET — agent commerce API",
    "version": "1.0.0",
    "summary": "Comandă dosare pentru instalații fotovoltaice, programatic, pentru agenți AI.",
    "description": "API pentru agenții AI care lucrează pentru firme de instalații fotovoltaice din România. Produse digitale (PDF + ZIP): dosar de predare (149 RON), dosar de prosumator (299 RON) și pachetul ambele (399 RON). Prețuri finale — firma nu este plătitoare de TVA (`vat: none`). Livrare prin email. Comenzile pot fi plătite prin transfer bancar (BANK) sau TON; confirmarea plății se face prin `/api/agent/order/verify-payment`. Documentație și condiții: https://solaris-cet.com/ro/terms.",
    "contact": {
      "name": "SOLARIS CET S.R.L.",
      "url": "https://solaris-cet.com",
      "email": "contact@solaris-cet.com"
    },
    "license": {
      "name": "Proprietary — SOLARIS CET S.R.L.",
      "url": "https://solaris-cet.com/ro/terms"
    }
  },
  "servers": [
    {
      "url": "https://solaris-cet.com",
      "description": "Producție"
    }
  ],
  "tags": [
    {
      "name": "agent",
      "description": "Fluxul comercial pentru agenți AI"
    },
    {
      "name": "public",
      "description": "Endpoint-uri publice de sănătate"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "tags": [
          "public"
        ],
        "operationId": "health",
        "summary": "Verifică starea serviciului",
        "responses": {
          "200": {
            "description": "Serviciul răspunde",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "ok"
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "status"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/quote": {
      "post": {
        "tags": [
          "agent"
        ],
        "operationId": "agentQuote",
        "summary": "Cere prețul pentru un produs (nu creează comandă)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteRequest"
              },
              "examples": {
                "prosumator": {
                  "value": {
                    "product": "dosar-prosumator",
                    "quantity": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Prețul calculat",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuoteResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/api/agent/order": {
      "post": {
        "tags": [
          "agent"
        ],
        "operationId": "agentCreateOrder",
        "summary": "Creează o comandă și instrucțiunile de plată",
        "description": "Acceptă headerul `Idempotency-Key`; aceeași cheie retrimisă returnează aceeași comandă, fără duplicare.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Cheie stabilă per încercare de comandă"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Comanda creată",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderResponse"
                }
              }
            }
          },
          "200": {
            "description": "Replay idempotent — aceeași comandă returnată",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "get": {
        "tags": [
          "agent"
        ],
        "operationId": "agentOrderStatusByQuery",
        "summary": "Status comandă după id (variantă query)",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^ORD-[0-9]{8}-[A-Z0-9]{6,20}$"
            },
            "example": "ORD-20261017-ab12"
          }
        ],
        "responses": {
          "200": {
            "description": "Statusul comenzii",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderStatus"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/agent/order/{orderId}": {
      "get": {
        "tags": [
          "agent"
        ],
        "operationId": "agentOrderStatus",
        "summary": "Status comandă după id (variantă path)",
        "parameters": [
          {
            "name": "orderId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^ORD-[0-9]{8}-[A-Z0-9]{6,20}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Statusul comenzii",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderStatus"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/agent/order/verify-payment": {
      "post": {
        "tags": [
          "agent"
        ],
        "operationId": "agentVerifyPaymentByQuery",
        "summary": "Verifică plata unei comenzi (variantă query)",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^ORD-[0-9]{8}-[A-Z0-9]{6,20}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Rezultatul verificării",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentVerification"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/agent/order/{orderId}/verify-payment": {
      "post": {
        "tags": [
          "agent"
        ],
        "operationId": "agentVerifyPayment",
        "summary": "Verifică plata unei comenzi (variantă path)",
        "parameters": [
          {
            "name": "orderId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^ORD-[0-9]{8}-[A-Z0-9]{6,20}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Rezultatul verificării",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentVerification"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ProductId": {
        "type": "string",
        "enum": [
          "dosar-predare",
          "dosar-prosumator",
          "pachet-ambele"
        ],
        "description": "dosar-predare = 149 RON, dosar-prosumator = 299 RON, pachet-ambele = 399 RON"
      },
      "QuoteRequest": {
        "type": "object",
        "required": [
          "product"
        ],
        "additionalProperties": false,
        "properties": {
          "product": {
            "$ref": "#/components/schemas/ProductId"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 1
          }
        }
      },
      "QuoteResponse": {
        "type": "object",
        "required": [
          "ok",
          "product",
          "quantity",
          "unitPriceRon",
          "totalRon",
          "currency",
          "vat"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "product": {
            "$ref": "#/components/schemas/ProductId"
          },
          "productName": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "unitPriceRon": {
            "type": "number"
          },
          "totalRon": {
            "type": "number"
          },
          "currency": {
            "type": "string",
            "const": "RON"
          },
          "vat": {
            "type": "string",
            "const": "none"
          },
          "deliveryEstimate": {
            "type": "string"
          },
          "nextStep": {
            "type": "string"
          },
          "company": {
            "$ref": "#/components/schemas/Company"
          }
        }
      },
      "OrderRequest": {
        "type": "object",
        "required": [
          "product",
          "customer"
        ],
        "additionalProperties": false,
        "properties": {
          "product": {
            "$ref": "#/components/schemas/ProductId"
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 1
          },
          "customer": {
            "type": "object",
            "required": [
              "email"
            ],
            "additionalProperties": false,
            "properties": {
              "email": {
                "type": "string",
                "format": "email"
              },
              "company": {
                "type": "string",
                "maxLength": 200
              },
              "companyCui": {
                "type": "string",
                "maxLength": 20
              }
            }
          },
          "projectRef": {
            "type": "string",
            "maxLength": 120
          },
          "notes": {
            "type": "string",
            "maxLength": 2000
          }
        }
      },
      "OrderResponse": {
        "type": "object",
        "required": [
          "ok",
          "order"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "order": {
            "$ref": "#/components/schemas/Order"
          },
          "nextStep": {
            "type": "string"
          },
          "endpoints": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "PaymentInstructions": {
        "oneOf": [
          {
            "title": "Bank transfer",
            "type": "object",
            "required": [
              "method"
            ],
            "properties": {
              "method": {
                "type": "string",
                "const": "BANK"
              },
              "proformaEmail": {
                "type": "string",
                "format": "email"
              },
              "note": {
                "type": "string"
              }
            }
          },
          {
            "title": "TON",
            "type": "object",
            "required": [
              "method"
            ],
            "properties": {
              "method": {
                "type": "string",
                "const": "TON"
              },
              "address": {
                "type": "string"
              },
              "amountTon": {
                "type": "number"
              },
              "memo": {
                "type": "string"
              },
              "expiresAt": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        ]
      },
      "OrderStatus": {
        "type": "object",
        "required": [
          "ok",
          "order"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "order": {
            "type": "object",
            "properties": {
              "orderId": {
                "type": "string"
              },
              "status": {
                "type": "string",
                "enum": [
                  "awaiting_payment",
                  "paid",
                  "in_production",
                  "delivered",
                  "cancelled"
                ]
              },
              "timeline": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "status": {
                      "type": "string"
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "PaymentVerification": {
        "type": "object",
        "required": [
          "ok",
          "verified"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "verified": {
            "type": "boolean"
          },
          "status": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          }
        }
      },
      "Company": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "cui": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "site": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "ok",
          "error"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "string"
          },
          "details": {
            "type": "object"
          }
        }
      },
      "Order": {
        "type": "object",
        "required": [
          "orderId",
          "status"
        ],
        "properties": {
          "orderId": {
            "type": "string",
            "pattern": "^ORD-[0-9]{8}-[A-Z0-9]{6,20}$"
          },
          "status": {
            "type": "string",
            "enum": [
              "awaiting_payment",
              "paid",
              "in_production",
              "delivered",
              "cancelled"
            ]
          },
          "product": {
            "$ref": "#/components/schemas/ProductId"
          },
          "quantity": {
            "type": "integer"
          },
          "totalRon": {
            "type": "number"
          },
          "currency": {
            "type": "string",
            "const": "RON"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "payment": {
            "oneOf": [
              {
                "title": "Bank transfer",
                "type": "object",
                "required": [
                  "method"
                ],
                "properties": {
                  "method": {
                    "type": "string",
                    "const": "BANK"
                  },
                  "proformaEmail": {
                    "type": "string",
                    "format": "email"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              },
              {
                "title": "TON",
                "type": "object",
                "required": [
                  "method"
                ],
                "properties": {
                  "method": {
                    "type": "string",
                    "const": "TON"
                  },
                  "address": {
                    "type": "string"
                  },
                  "amountTon": {
                    "type": "number"
                  },
                  "memo": {
                    "type": "string"
                  },
                  "expiresAt": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            ]
          },
          "statusUrl": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Cerere invalidă",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resursa nu există",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Operațiune nepermisă în mediul curent",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Prea multe cereri",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}