{
  "openapi": "3.0.0",
  "info": {
    "title": "Recipients API",
    "version": "1.0.0",
    "description": "API for managing payment recipients"
  },
  "tags": [
    {
      "name": "Recipients",
      "description": "Payment recipient operations"
    }
  ],
  "paths": {
    "/v1/customers/{customer_id}/recipients": {
      "post": {
        "summary": "Create recipient",
        "description": "Create a new payment recipient",
        "tags": ["Recipients"],
        "parameters": [
          {
            "name": "customer_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecipientInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recipient created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "recipient": {
                      "$ref": "#/components/schemas/Recipient"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenError"
          },
          "422": {
            "$ref": "#/components/responses/InvalidBICError"
          }
        }
      },
      "get": {
        "summary": "Get all recipients",
        "description": "Retrieve all recipients with optional filtering",
        "tags": ["Recipients"],
        "parameters": [
          {
            "name": "customer_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["business", "personal"]
            }
          },
          {
            "name": "country",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 2
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Recipients retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecipientsResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenError"
          }
        }
      }
    },
    "/v1/recipients/{id}": {
      "get": {
        "summary": "Get recipient",
        "description": "Retrieve a specific recipient by ID",
        "tags": ["Recipients"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Recipient retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Recipient"
                }
              }
            }
          },
          "404": {
            "description": "Recipient not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete recipient",
        "description": "Delete a recipient",
        "tags": ["Recipients"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Recipient deleted successfully"
          },
          "404": {
            "description": "Recipient not found"
          }
        }
      }
    },
    "/v1/customers/{customer_id}/recipients/{id}": {
      "put": {
        "summary": "Update recipient",
        "description": "Update an existing recipient",
        "tags": ["Recipients"],
        "parameters": [
          {
            "name": "customer_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecipientInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Recipient updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "recipient": {
                      "$ref": "#/components/schemas/Recipient"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "404": {
            "description": "Recipient not found"
          }
        }
      }
    },
    "/v1/customers/{customer_id}/recipients/search": {
      "post": {
        "summary": "Search recipients",
        "description": "Search recipients with complex filters",
        "tags": ["Recipients"],
        "parameters": [
          {
            "name": "customer_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecipientSearchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecipientsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "RecipientInput": {
        "type": "object",
        "required": [
          "iban",
          "legal_name",
          "country",
          "city",
          "legal_address",
          "bic",
          "bank",
          "type"
        ],
        "properties": {
          "iban": {
            "type": "string"
          },
          "legal_name": {
            "type": "string"
          },
          "country": {
            "type": "string",
            "minLength": 2,
            "maxLength": 2
          },
          "city": {
            "type": "string"
          },
          "legal_address": {
            "type": "string"
          },
          "bic": {
            "type": "string",
            "pattern": "^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$"
          },
          "bank": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": ["business", "personal"]
          },
          "intermediate_bic": {
            "type": "string",
            "pattern": "^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$"
          },
          "intermediate_bank": {
            "type": "string"
          },
          "intermediate_route": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "reference": {
            "type": "string"
          }
        }
      },
      "Recipient": {
        "allOf": [
          {
            "$ref": "#/components/schemas/RecipientInput"
          },
          {
            "type": "object",
            "required": ["id", "customer_id"],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "customer_id": {
                "type": "string",
                "format": "uuid"
              }
            }
          }
        ]
      },
      "RecipientsResponse": {
        "type": "object",
        "properties": {
          "recipients": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Recipient"
            }
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "has_more": {
            "type": "boolean"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "RecipientSearchRequest": {
        "type": "object",
        "properties": {
          "iban": {
            "type": "string"
          },
          "legal_name": {
            "type": "string"
          },
          "bic": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": ["business", "personal"]
          },
          "country": {
            "type": "string",
            "minLength": 2,
            "maxLength": 2
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      }
    },
    "responses": {
      "ValidationError": {
        "description": "Invalid input data",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "code": "recipients.invalid_bic_format",
              "message": "Invalid BIC format"
            }
          }
        }
      },
      "UnauthorizedError": {
        "description": "Authentication required",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "code": "common.unauthorized",
              "message": "Authentication required"
            }
          }
        }
      },
      "ForbiddenError": {
        "description": "Insufficient permissions",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "code": "common.forbidden",
              "message": "Insufficient permissions"
            }
          }
        }
      },
      "NotFoundError": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "code": "db.no_rows",
              "message": "Recipient not found"
            }
          }
        }
      },
      "InvalidBICError": {
        "description": "Invalid BIC format",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "code": "recipients.invalid_bic_format",
              "message": "Invalid BIC format"
            }
          }
        }
      },
      "InvalidBICLengthError": {
        "description": "Invalid BIC length",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "code": "recipients.invalid_bic_length",
              "message": "BIC length must be 8 or 11 characters"
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ]
} 