{
  "openapi": "3.0.3",
  "info": {
    "title": "Dhanita Finance CRM API",
    "description": "API documentation for adding loan and financial services inside a website, mobile app, CRM, ERP, admin panel, lead management system, or third party portal.",
    "version": "1.0.0",
    "contact": {
      "name": "Dhanita Technologies API Support",
      "email": "support@dhanitatechnologies.com"
    }
  },
  "servers": [
    {
      "url": "https://dhanitatechnologies.com/api/v1",
      "description": "Production API"
    }
  ],
  "externalDocs": {
    "description": "Swagger Documentation",
    "url": "https://dhanitatechnologies.com/api-docs-v1"
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "Products",
      "description": "Loan and financial product APIs"
    },
    {
      "name": "Leads",
      "description": "Lead creation, update, view, journey, and disbursement APIs"
    },
    {
      "name": "Documents",
      "description": "Customer document upload and update APIs"
    },
    {
      "name": "Communication",
      "description": "Lead notes, customer conversation, RM communication, and follow-up APIs"
    },
    {
      "name": "RM and Lender",
      "description": "Relationship manager and lender mapping APIs"
    },
    {
      "name": "Status",
      "description": "Status master and real-time application tracking APIs"
    }
  ],
  "paths": {
    "/products": {
      "get": {
        "tags": ["Products"],
        "summary": "Get active finance products",
        "description": "Returns active loan and financial products available for API partners.",
        "responses": {
          "200": {
            "description": "Active products returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/products/categories": {
      "get": {
        "tags": ["Products"],
        "summary": "Get product categories",
        "responses": {
          "200": {
            "description": "Product categories returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CategoryListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/products/lender-mapping": {
      "get": {
        "tags": ["Products"],
        "summary": "Get lender product mapping",
        "parameters": [
          {
            "name": "product_code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lender mapping returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LenderMappingResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads": {
      "post": {
        "tags": ["Leads"],
        "summary": "Create customer lead",
        "description": "Submit customer basic details for a selected financial product.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateLeadRequest"
              },
              "example": {
                "product": "Personal Loan",
                "customer_name": "Rahul Sharma",
                "mobile": "9876543210",
                "loan_amount": 500000,
                "dsa_code": "DSA12345"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Lead created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads/{lead_id}": {
      "get": {
        "tags": ["Leads"],
        "summary": "View lead details",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "responses": {
          "200": {
            "description": "Lead details returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadResponse"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": ["Leads"],
        "summary": "Update lead details",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateLeadRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lead updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads/{lead_id}/journey": {
      "get": {
        "tags": ["Leads"],
        "summary": "Get lead journey",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "responses": {
          "200": {
            "description": "Lead journey returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadJourneyResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads/{lead_id}/status": {
      "get": {
        "tags": ["Status"],
        "summary": "Get real-time lead status",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "responses": {
          "200": {
            "description": "Lead status returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadStatusResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads/{lead_id}/disbursement": {
      "get": {
        "tags": ["Leads"],
        "summary": "Get lead disbursement details",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "responses": {
          "200": {
            "description": "Disbursement details returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DisbursementResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads/{lead_id}/documents": {
      "post": {
        "tags": ["Documents"],
        "summary": "Upload customer document",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/UploadDocumentRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Document uploaded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads/{lead_id}/documents/{document_id}": {
      "patch": {
        "tags": ["Documents"],
        "summary": "Update document details",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          },
          {
            "$ref": "#/components/parameters/DocumentId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateDocumentRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads/{lead_id}/notes": {
      "post": {
        "tags": ["Communication"],
        "summary": "Add lead note or follow-up update",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateNoteRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Note added",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NoteResponse"
                }
              }
            }
          }
        }
      }
    },
    "/leads/{lead_id}/rm": {
      "get": {
        "tags": ["RM and Lender"],
        "summary": "Get assigned RM and lender details",
        "parameters": [
          {
            "$ref": "#/components/parameters/LeadId"
          }
        ],
        "responses": {
          "200": {
            "description": "RM and lender details returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RmLenderResponse"
                }
              }
            }
          }
        }
      }
    },
    "/statuses": {
      "get": {
        "tags": ["Status"],
        "summary": "Get all lead statuses",
        "responses": {
          "200": {
            "description": "Statuses returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatusListResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "parameters": {
      "LeadId": {
        "name": "lead_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "example": "LD202605180001"
        }
      },
      "DocumentId": {
        "name": "document_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "example": "DOC1001"
        }
      }
    },
    "schemas": {
      "Product": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "example": "PERSONAL_LOAN"
          },
          "name": {
            "type": "string",
            "example": "Personal Loan"
          },
          "category": {
            "type": "string",
            "example": "Loan"
          },
          "status": {
            "type": "string",
            "example": "active"
          }
        }
      },
      "ProductListResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Product"
            }
          }
        }
      },
      "CategoryListResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": ["Instant Loan", "KYC Loan", "Personal Loan", "Business Loan", "Home Loan", "Car Loan", "Credit Card", "Saving Account", "Demat Account", "Insurance Services"]
          }
        }
      },
      "LenderMappingResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "product_code": {
                  "type": "string",
                  "example": "PERSONAL_LOAN"
                },
                "lender_name": {
                  "type": "string",
                  "example": "Partner Lender"
                },
                "status": {
                  "type": "string",
                  "example": "active"
                }
              }
            }
          }
        }
      },
      "CreateLeadRequest": {
        "type": "object",
        "required": ["product", "customer_name", "mobile"],
        "properties": {
          "product": {
            "type": "string",
            "example": "Personal Loan"
          },
          "customer_name": {
            "type": "string",
            "example": "Rahul Sharma"
          },
          "mobile": {
            "type": "string",
            "example": "9876543210"
          },
          "email": {
            "type": "string",
            "format": "email",
            "example": "rahul@example.com"
          },
          "loan_amount": {
            "type": "number",
            "example": 500000
          },
          "city": {
            "type": "string",
            "example": "Faridabad"
          },
          "dsa_code": {
            "type": "string",
            "example": "DSA12345"
          }
        }
      },
      "UpdateLeadRequest": {
        "type": "object",
        "properties": {
          "customer_name": {
            "type": "string",
            "example": "Rahul Sharma"
          },
          "loan_amount": {
            "type": "number",
            "example": 650000
          },
          "city": {
            "type": "string",
            "example": "Delhi"
          }
        }
      },
      "Lead": {
        "type": "object",
        "properties": {
          "lead_id": {
            "type": "string",
            "example": "LD202605180001"
          },
          "product": {
            "type": "string",
            "example": "Personal Loan"
          },
          "customer_name": {
            "type": "string",
            "example": "Rahul Sharma"
          },
          "mobile": {
            "type": "string",
            "example": "9876543210"
          },
          "status": {
            "type": "string",
            "example": "document_pending"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "LeadResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "$ref": "#/components/schemas/Lead"
          }
        }
      },
      "LeadJourneyResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string",
                  "example": "document_pending"
                },
                "note": {
                  "type": "string",
                  "example": "KYC document required."
                },
                "updated_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "LeadStatusResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "object",
            "properties": {
              "lead_id": {
                "type": "string",
                "example": "LD202605180001"
              },
              "status": {
                "type": "string",
                "example": "under_review"
              },
              "message": {
                "type": "string",
                "example": "Application is under lender review."
              }
            }
          }
        }
      },
      "DisbursementResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "object",
            "properties": {
              "lead_id": {
                "type": "string",
                "example": "LD202605180001"
              },
              "approved_amount": {
                "type": "number",
                "example": 450000
              },
              "disbursement_status": {
                "type": "string",
                "example": "pending"
              },
              "disbursement_date": {
                "type": "string",
                "format": "date",
                "nullable": true
              }
            }
          }
        }
      },
      "UploadDocumentRequest": {
        "type": "object",
        "required": ["document_type", "file"],
        "properties": {
          "document_type": {
            "type": "string",
            "example": "PAN"
          },
          "file": {
            "type": "string",
            "format": "binary"
          }
        }
      },
      "UpdateDocumentRequest": {
        "type": "object",
        "properties": {
          "document_type": {
            "type": "string",
            "example": "AADHAAR"
          },
          "status": {
            "type": "string",
            "example": "verified"
          }
        }
      },
      "DocumentResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "object",
            "properties": {
              "document_id": {
                "type": "string",
                "example": "DOC1001"
              },
              "document_type": {
                "type": "string",
                "example": "PAN"
              },
              "status": {
                "type": "string",
                "example": "uploaded"
              }
            }
          }
        }
      },
      "CreateNoteRequest": {
        "type": "object",
        "required": ["note"],
        "properties": {
          "note": {
            "type": "string",
            "example": "Customer asked for callback tomorrow."
          },
          "type": {
            "type": "string",
            "example": "follow_up"
          }
        }
      },
      "NoteResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "message": {
            "type": "string",
            "example": "Note added successfully."
          }
        }
      },
      "RmLenderResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "object",
            "properties": {
              "rm_name": {
                "type": "string",
                "example": "Assigned RM"
              },
              "rm_mobile": {
                "type": "string",
                "example": "9999999999"
              },
              "lender_name": {
                "type": "string",
                "example": "Partner Lender"
              },
              "lender_status": {
                "type": "string",
                "example": "under_review"
              }
            }
          }
        }
      },
      "StatusListResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": ["new", "document_pending", "under_review", "approved", "rejected", "disbursed"]
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "message": {
            "type": "string",
            "example": "Validation failed."
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}