{
  "openapi": "3.1.0",
  "info": {
    "title": "Asigurari AI (demo SurCod)",
    "version": "0.3.0",
    "description": "REST API pentru agenti AI care cer cotatii RCA, cumpara si primesc polite. Aceleasi operatii ca serverul MCP de la /mcp. DEMO: date simulate."
  },
  "servers": [
    {
      "url": "https://asigurari.surcod.ro/api/v1"
    }
  ],
  "paths": {
    "/products": {
      "get": {
        "operationId": "list_products",
        "summary": "Produse disponibile",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "products": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  },
                  "required": [
                    "products"
                  ]
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/products/rca/requirements": {
      "get": {
        "operationId": "get_requirements",
        "summary": "Date necesare pentru RCA",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/rca/vehicle": {
      "post": {
        "operationId": "identify_vehicle",
        "summary": "Identifica vehiculul dupa VIN",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "vin": {
                    "type": "string",
                    "minLength": 17,
                    "maxLength": 17
                  }
                },
                "required": [
                  "vin"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "found": {
                      "type": "boolean"
                    },
                    "vehicle": {
                      "type": "object"
                    },
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "found"
                  ]
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/rca/quotes": {
      "post": {
        "operationId": "request_quotes",
        "summary": "Cotatii RCA sortate dupa pret",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "vin": {
                    "type": "string",
                    "description": "Seria de șasiu (17 caractere). Alternativ, trimite vehicle."
                  },
                  "vehicle": {
                    "type": "object",
                    "additionalProperties": false,
                    "description": "Datele mașinii, când nu există VIN sau identify_vehicle nu a găsit-o.",
                    "properties": {
                      "vin": {
                        "type": "string"
                      },
                      "category": {
                        "type": "string",
                        "enum": [
                          "autoturism"
                        ],
                        "default": "autoturism"
                      },
                      "make": {
                        "type": "string"
                      },
                      "model": {
                        "type": "string"
                      },
                      "year": {
                        "type": "integer",
                        "minimum": 1950
                      },
                      "fuel": {
                        "type": "string",
                        "enum": [
                          "benzina",
                          "motorina",
                          "hibrid",
                          "electric",
                          "gpl"
                        ]
                      },
                      "engine_cc": {
                        "type": "integer",
                        "minimum": 0,
                        "description": "Cilindree în cmc; 0 pentru electric."
                      },
                      "power_kw": {
                        "type": "number",
                        "minimum": 1
                      },
                      "seats": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 9
                      },
                      "max_mass_kg": {
                        "type": "integer",
                        "minimum": 500
                      }
                    },
                    "required": [
                      "make",
                      "model",
                      "year",
                      "fuel",
                      "engine_cc",
                      "power_kw",
                      "seats"
                    ]
                  },
                  "registration_number": {
                    "type": "string",
                    "description": "Numărul de înmatriculare, ex. CJ12ABC. Opțional."
                  },
                  "usage": {
                    "type": "string",
                    "enum": [
                      "personal",
                      "taxi_ridesharing",
                      "curierat",
                      "inchiriere"
                    ],
                    "default": "personal"
                  },
                  "owner": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "PF",
                          "PJ"
                        ],
                        "default": "PF",
                        "description": "PF persoană fizică, PJ persoană juridică."
                      },
                      "county": {
                        "type": "string",
                        "enum": [
                          "AB",
                          "AR",
                          "AG",
                          "BC",
                          "BH",
                          "BN",
                          "BT",
                          "BR",
                          "BV",
                          "B",
                          "BZ",
                          "CL",
                          "CS",
                          "CJ",
                          "CT",
                          "CV",
                          "DB",
                          "DJ",
                          "GL",
                          "GR",
                          "GJ",
                          "HR",
                          "HD",
                          "IL",
                          "IS",
                          "IF",
                          "MM",
                          "MH",
                          "MS",
                          "NT",
                          "OT",
                          "PH",
                          "SJ",
                          "SM",
                          "SB",
                          "SV",
                          "TR",
                          "TM",
                          "TL",
                          "VL",
                          "VS",
                          "VN"
                        ],
                        "description": "Codul județului proprietarului; B pentru București."
                      },
                      "driver_birth_year": {
                        "type": "integer",
                        "description": "Anul nașterii șoferului principal."
                      },
                      "license_year": {
                        "type": "integer",
                        "description": "Anul obținerii permisului."
                      }
                    },
                    "required": [
                      "county",
                      "driver_birth_year",
                      "license_year"
                    ]
                  },
                  "declared_bonus_malus": {
                    "type": "string",
                    "enum": [
                      "M8",
                      "M7",
                      "M6",
                      "M5",
                      "M4",
                      "M3",
                      "M2",
                      "M1",
                      "B0",
                      "B1",
                      "B2",
                      "B3",
                      "B4",
                      "B5",
                      "B6",
                      "B7",
                      "B8",
                      "B9",
                      "B10",
                      "B11",
                      "B12",
                      "B13",
                      "B14"
                    ],
                    "description": "Opțional; implicit B0. Se verifică la cumpărare, iar dacă diferă prețul se recalculează."
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date",
                    "description": "YYYY-MM-DD, cel mai devreme mâine, cel mult peste 60 de zile. Implicit mâine."
                  },
                  "months": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 12,
                    "default": 12
                  },
                  "direct_settlement": {
                    "type": "boolean",
                    "default": false,
                    "description": "Clauza de decontare directă (cost suplimentar). Opțională."
                  }
                },
                "required": [
                  "owner"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "quotes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "offer_id": {
                            "type": "string"
                          },
                          "insurer_name": {
                            "type": "string"
                          },
                          "premium_ron": {
                            "type": "number"
                          },
                          "months": {
                            "type": "integer"
                          },
                          "start_date": {
                            "type": "string"
                          },
                          "end_date": {
                            "type": "string"
                          },
                          "bonus_malus": {
                            "type": "string"
                          },
                          "commission_pct": {
                            "type": "number"
                          },
                          "valid_until": {
                            "type": "string"
                          },
                          "offer_pdf_url": {
                            "type": "string"
                          },
                          "ipid_url": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "declined": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "cheapest_offer_id": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "quotes"
                  ]
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/offers/{id}": {
      "get": {
        "operationId": "get_offer",
        "summary": "Detaliile unei oferte",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "offer_id"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "offer_id": {
                      "type": "string"
                    },
                    "insurer_name": {
                      "type": "string"
                    },
                    "premium_ron": {
                      "type": "number"
                    },
                    "months": {
                      "type": "integer"
                    },
                    "start_date": {
                      "type": "string"
                    },
                    "end_date": {
                      "type": "string"
                    },
                    "bonus_malus": {
                      "type": "string"
                    },
                    "commission_pct": {
                      "type": "number"
                    },
                    "valid_until": {
                      "type": "string"
                    },
                    "offer_pdf_url": {
                      "type": "string"
                    },
                    "ipid_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/purchases": {
      "post": {
        "operationId": "start_purchase",
        "summary": "Porneste cumpararea; intoarce purchase_url",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "offer_id": {
                    "type": "string"
                  }
                },
                "required": [
                  "offer_id"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "purchase_id": {
                      "type": "string"
                    },
                    "purchase_url": {
                      "type": "string"
                    },
                    "amount_ron": {
                      "type": "number"
                    },
                    "expires_at": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "purchase_id",
                    "purchase_url"
                  ]
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/purchases/{id}": {
      "get": {
        "operationId": "get_purchase_status",
        "summary": "Starea cumpararii",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "purchase_id"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "awaiting_confirmation",
                        "paid_issued",
                        "expired"
                      ]
                    },
                    "policy": {
                      "type": "object",
                      "properties": {
                        "policy_id": {
                          "type": "string"
                        },
                        "series": {
                          "type": "string"
                        },
                        "number": {
                          "type": "string"
                        },
                        "insurer_name": {
                          "type": "string"
                        },
                        "start_date": {
                          "type": "string"
                        },
                        "end_date": {
                          "type": "string"
                        },
                        "premium_ron": {
                          "type": "number"
                        },
                        "policy_pdf_url": {
                          "type": "string"
                        }
                      }
                    },
                    "mandate": {
                      "type": [
                        "object",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "status"
                  ]
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/mandate-purchases": {
      "post": {
        "operationId": "purchase_with_mandate",
        "summary": "Cumparare directa pe baza de mandat",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "offer_id": {
                    "type": "string"
                  },
                  "mandate_token": {
                    "type": "string",
                    "description": "Tokenul primit o singură dată prin get_purchase_status. Nu îl afișa utilizatorului."
                  },
                  "idempotency_key": {
                    "type": "string",
                    "maxLength": 100,
                    "description": "Recomandat: o cheie unică per intenție de cumpărare. La retry cu aceeași cheie primești aceeași poliță, fără a doua plată."
                  },
                  "user_confirmation": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "confirmed": {
                        "type": "boolean",
                        "const": true
                      },
                      "summary_shown": {
                        "type": "string",
                        "minLength": 10
                      }
                    },
                    "required": [
                      "confirmed",
                      "summary_shown"
                    ]
                  }
                },
                "required": [
                  "offer_id",
                  "mandate_token",
                  "user_confirmation"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "policy": {
                      "type": "object",
                      "properties": {
                        "policy_id": {
                          "type": "string"
                        },
                        "series": {
                          "type": "string"
                        },
                        "number": {
                          "type": "string"
                        },
                        "insurer_name": {
                          "type": "string"
                        },
                        "start_date": {
                          "type": "string"
                        },
                        "end_date": {
                          "type": "string"
                        },
                        "premium_ron": {
                          "type": "number"
                        },
                        "policy_pdf_url": {
                          "type": "string"
                        }
                      }
                    },
                    "mandate_remaining_ron": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "status"
                  ]
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/policies/{id}": {
      "get": {
        "operationId": "get_policy",
        "summary": "Polita emisa",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "policy_id"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "policy_id": {
                      "type": "string"
                    },
                    "series": {
                      "type": "string"
                    },
                    "number": {
                      "type": "string"
                    },
                    "insurer_name": {
                      "type": "string"
                    },
                    "start_date": {
                      "type": "string"
                    },
                    "end_date": {
                      "type": "string"
                    },
                    "premium_ron": {
                      "type": "number"
                    },
                    "policy_pdf_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/policies/{id}/renewal-quotes": {
      "post": {
        "operationId": "renew_policy",
        "summary": "Cotatii de reinnoire, cu inceput a doua zi dupa expirare",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "policy_id"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "renewal_of": {
                      "type": "object"
                    },
                    "quotes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "offer_id": {
                            "type": "string"
                          },
                          "insurer_name": {
                            "type": "string"
                          },
                          "premium_ron": {
                            "type": "number"
                          },
                          "months": {
                            "type": "integer"
                          },
                          "start_date": {
                            "type": "string"
                          },
                          "end_date": {
                            "type": "string"
                          },
                          "bonus_malus": {
                            "type": "string"
                          },
                          "valid_until": {
                            "type": "string"
                          },
                          "offer_pdf_url": {
                            "type": "string"
                          },
                          "ipid_url": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "declined": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "cheapest_offer_id": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "existing_policy": {
                      "type": [
                        "object",
                        "null"
                      ]
                    },
                    "next_step": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "quotes",
                    "renewal_of"
                  ]
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/policy-history": {
      "post": {
        "operationId": "list_policies",
        "summary": "Politele emise pentru un vehicul sau un mandat",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "vin": {
                    "type": "string",
                    "description": "Seria de șasiu (17 caractere)."
                  },
                  "registration_number": {
                    "type": "string",
                    "description": "Numărul de înmatriculare, ex. CJ12ABC."
                  },
                  "mandate_token": {
                    "type": "string",
                    "description": "Tokenul de mandat; întoarce polițele cumpărate sub mandat, cu linkuri."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "lookup": {
                      "type": "string"
                    },
                    "policies": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "policy_id": {
                            "type": "string",
                            "description": "Doar la căutarea după mandate_token."
                          },
                          "series": {
                            "type": "string"
                          },
                          "number": {
                            "type": "string"
                          },
                          "insurer_name": {
                            "type": "string"
                          },
                          "vehicle": {
                            "type": "string"
                          },
                          "registration_number": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "start_date": {
                            "type": "string"
                          },
                          "end_date": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "active",
                              "upcoming",
                              "expired"
                            ]
                          },
                          "policy_pdf_url": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  },
                  "required": [
                    "policies"
                  ]
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/mandates/revoke": {
      "post": {
        "operationId": "revoke_mandate",
        "summary": "Revoca un mandat",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "mandate_token": {
                    "type": "string"
                  }
                },
                "required": [
                  "mandate_token"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "revoked": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "4XX": {
            "description": "Eroare cu cod stabil",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "field": {
                "type": "string"
              },
              "hint": {
                "type": "string"
              },
              "details": {
                "type": "object"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        }
      }
    }
  }
}
