{
  "openapi": "1.0.0",
  "info": {
    "title": "Vendor API Schema",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://lending-uat.creditfair.in",
      "description": "lending uat server"
    }
  ],
  "paths": {
    "/customerRest/customerSrv/createCustomer": {
      "post": {
        "tags": [
          "Vendor Create Customer"
        ],
        "functions": {
          "init": [
            {
              "operation": "setData",
              "stateKey": "request_id",
              "value": "UUID"
            },
            {
              "operation": "query",
              "queryType": "insert",
              "table": "vendor_api_request",
              "stateKey": "vendor_api_request_id",
              "values": {
                "created_at": "datetime.CUR_TIMESTAMP",
                "vendor_id": "$vendor_details.vendor_id",
                "request": "json_dumps->$request"
              },
              "auto_id": "id"
            },
            {
              "operation": "setData",
              "value": "set_address_value->$request.addresses,current",
              "stateKey": "current_address"
            },
            {
              "operation": "setData",
              "value": "set_address_value->$request.addresses,permanent",
              "stateKey": "permanent_address"
            }
          ]
        },
        "requestBody": {
          "content": {
            "type": "object",
            "properties": {
              "loanId": {
                "type": "string",
                "message": {
                  "return_code": "201002",
                  "message": "Loan_ID is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "personalEmailId": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$",
                "message": {
                  "return_code": "201002",
                  "message": "Invalid Email Address",
                  "CF_code": "CF300"
                }
              },
              "aadhaarNumber": {
                "type": "string",
                "pattern": "^[0-9]{12}$",
                "message": {
                  "return_code": "201002",
                  "message": "Invalid Aadhaar Number",
                  "CF_code": "CF300"
                }
              },
              "companyPincode": {
                "type": "string",
                "pattern": "^[0-9]{6}$",
                "message": {
                  "return_code": "201002",
                  "message": "Pincode must be 6 digits",
                  "CF_code": "CF300"
                }
              },
              "bankDetails": {
                "type": "object",
                "properties": {
                  "accountHolderName": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150,
                    "message": {
                      "return_code": "201002",
                      "message": "Account Holder Name is mandatory",
                      "CF_code": "CF300"
                    }
                  },
                  "accountNumber": {
                    "type": "string",
                    "pattern": "^[0-9]{9,18}$",
                    "message": {
                      "return_code": "201002",
                      "message": "Invalid Account Number",
                      "CF_code": "CF300"
                    }
                  },
                  "ifscCode": {
                    "type": "string",
                    "pattern": "^[A-Z]{4}0[A-Z0-9]{6}$",
                    "message": {
                      "return_code": "201002",
                      "message": "Invalid IFSC Code",
                      "CF_code": "CF300"
                    }
                  },
                  "bankName": {
                    "type": "string",
                    "message": {
                      "return_code": "201002",
                      "message": "bankName is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "accountType": {
                    "type": "string",
                    "enum": [
                      "Savings",
                      "Current",
                      "Cash Credit (CC)",
                      "Overdraft (OD)"
                    ],
                    "message": {
                      "return_code": "201002",
                      "message": "Invalid Account Type",
                      "CF_code": "CF300"
                    }
                  },
                  "minBankTransactionInMonth": {
                    "type": "integer",
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "Transaction count cannot be negative",
                      "CF_code": "CF300"
                    }
                  },
                  "noOfCreditTransactionInMonth": {
                    "type": "integer",
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "noOfCreditTransactionInMonth is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "noOfDebitTransactionInMonth": {
                    "type": "integer",
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "noOfDebitTransactionInMonth is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "noOfInwardTransactions": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "noOfInwardTransactions is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "noOfChequeBounces": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "noOfChequeBounces is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "noOfInwardChequeReturns": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "noOfInwardChequeReturns is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "noOfOutwardChequeReturns": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "maxCcOdUtilization": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "nachReturnInLast3Months": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  }
                }
              },
              "dateOfBirth": {
                "type": "string",
                "pattern": "^\\d{4}\\-(0?[1-9]|1[012])\\-(0?[1-9]|[12][0-9]|3[01])$",
                "message": {
                  "return_code": "201002",
                  "message": "dateOfBirth is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "gender": {
                "type": "string",
                "enum": [
                  "Male",
                  "Female",
                  "Other"
                ],
                "message": {
                  "return_code": "201002",
                  "message": "gender is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "maritalStatus": {
                "type": "string",
                "enum": [
                  "Unmarried",
                  "Married",
                  "Divorced",
                  "Widowed"
                ],
                "message": {
                  "return_code": "201002",
                  "message": "maritalStatus is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "nationality": {
                "type": "string",
                "enum": [
                  "Indian"
                ],
                "message": {
                  "return_code": "201002",
                  "message": "nationality is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "entityType": {
                "type": "string",
                "enum": [
                  "Sole Proprietor"
                ],
                "message": {
                  "return_code": "201002",
                  "message": "entityType is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "addresses": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "addressType": {
                      "description": "Error",
                      "type": "string",
                      "enum": [
                        "current",
                        "permanent"
                      ],
                      "message": {
                        "return_code": "201002",
                        "message": "Address type is required",
                        "CF_code": "CF300",
                        "pattern": ""
                      }
                    },
                    "addressLine": {
                      "description": "Error",
                      "type": [
                        "string"
                      ],
                      "minLength": 1,
                      "message": {
                        "return_code": "201002",
                        "message": "Address line is required.",
                        "CF_code": "CF300",
                        "pattern": ""
                      }
                    },
                    "city": {
                      "description": "Error",
                      "type": [
                        "string"
                      ],
                      "minLength": 1,
                      "message": {
                        "return_code": "201002",
                        "message": "City is required",
                        "CF_code": "CF300",
                        "pattern": ""
                      }
                    },
                    "district": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "message": {
                        "return_code": "201002",
                        "message": "District is required",
                        "CF_code": "CF300",
                        "pattern": ""
                      }
                    },
                    "state": {
                      "description": "Error",
                      "anyOf": [
                        {
                          "type": [
                            "string"
                          ],
                          "enum": [
                            "Andhra Pradesh",
                            "Arunachal Pradesh",
                            "Assam",
                            "Bihar",
                            "Chhattisgarh",
                            "Goa",
                            "Gujarat",
                            "Haryana",
                            "Himachal Pradesh",
                            "Jharkhand",
                            "Karnataka",
                            "Kerala",
                            "Madhya Pradesh",
                            "Maharashtra",
                            "Manipur",
                            "Meghalaya",
                            "Mizoram",
                            "Nagaland",
                            "Odisha",
                            "Punjab",
                            "Rajasthan",
                            "Sikkim",
                            "Tamil Nadu",
                            "Telangana",
                            "Tripura",
                            "Uttar Pradesh",
                            "Uttarakhand",
                            "West Bengal",
                            "Andaman and Nicobar Islands",
                            "Chandigarh",
                            "Dadra and Nagar Haveli and Daman and Diu",
                            "Delhi",
                            "Jammu and Kashmir",
                            "Ladakh",
                            "Lakshadweep",
                            "Puducherry"
                          ],
                          "message": {
                            "return_code": "201002",
                            "message": "State is required",
                            "CF_code": "CF300",
                            "pattern": ""
                          }
                        }
                      ]
                    },
                    "pincode": {
                      "type": [
                        "string"
                      ],
                      "minLength": 6,
                      "maxLength": 6,
                      "message": {
                        "return_code": "201002",
                        "message": "Pincode is required",
                        "CF_code": "CF300",
                        "pattern": ""
                      }
                    }
                  },
                  "required": [
                    "addressType",
                    "addressLine",
                    "district",
                    "city",
                    "state",
                    "pincode"
                  ]
                }
              },
              "companyDetails": {
                "type": "object",
                "properties": {
                  "companyName": {
                    "type": "string",
                    "maxLength": 200,
                    "message": {
                      "return_code": "201002",
                      "message": "companyName is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "companyAddress": {
                    "type": "string",
                    "maxLength": 500,
                    "message": {
                      "return_code": "201002",
                      "message": "companyAddress is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "companyCity": {
                    "type": "string",
                    "pattern": "^[a-zA-Z\\s]+$",
                    "message": {
                      "return_code": "201002",
                      "message": "companyCity is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "companyDistrict": {
                    "type": "string",
                    "pattern": "^[a-zA-Z\\s]+$",
                    "message": {
                      "return_code": "201002",
                      "message": "companyDistrict is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "companyState": {
                    "type": "string",
                    "message": {
                      "return_code": "201002",
                      "message": "companyState is mandatory or invalid",
                      "CF_code": "CF300"
                    },
                    "enum": [
                      "Andhra Pradesh",
                      "Arunachal Pradesh",
                      "Assam",
                      "Bihar",
                      "Chhattisgarh",
                      "Goa",
                      "Gujarat",
                      "Haryana",
                      "Himachal Pradesh",
                      "Jharkhand",
                      "Karnataka",
                      "Kerala",
                      "Madhya Pradesh",
                      "Maharashtra",
                      "Manipur",
                      "Meghalaya",
                      "Mizoram",
                      "Nagaland",
                      "Odisha",
                      "Punjab",
                      "Rajasthan",
                      "Sikkim",
                      "Tamil Nadu",
                      "Telangana",
                      "Tripura",
                      "Uttar Pradesh",
                      "Uttarakhand",
                      "West Bengal",
                      "Andaman and Nicobar Islands",
                      "Chandigarh",
                      "Dadra and Nagar Haveli and Daman and Diu",
                      "Delhi",
                      "Jammu and Kashmir",
                      "Ladakh",
                      "Lakshadweep",
                      "Puducherry"
                    ]
                  },
                  "companyPincode": {
                    "type": "string",
                    "pattern": "^[0-9]{6}$",
                    "message": {
                      "return_code": "201002",
                      "message": "Pincode must be 6 digits",
                      "CF_code": "CF300"
                    }
                  },
                  "industryType": {
                    "type": "string",
                    "enum": [
                      "Manufacturing",
                      "Retail",
                      "Wholesale",
                      "Trading",
                      "Agriculture",
                      "Construction",
                      "Transportation",
                      "Healthcare",
                      "Education",
                      "Professional Services",
                      "Hospitality",
                      "Others"
                    ],
                    "message": {
                      "return_code": "201002",
                      "message": "industryType is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "businessVintage": {
                    "type": "integer",
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "businessVintage is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "udyamNumber": {
                    "type": "string",
                    "pattern": "^UDYAM-[A-Z]{2}-\\d{2}-\\d{7}$",
                    "message": {
                      "return_code": "201002",
                      "message": "udyamNumber is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "annualTurnover": {
                    "type": "number",
                    "minimum": 1,
                    "message": {
                      "return_code": "201002",
                      "message": "annualTurnover is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "gst": {
                    "type": "string",
                    "message": {
                      "return_code": "201002",
                      "message": "gst is invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "cin": {
                    "type": "string",
                    "message": {
                      "return_code": "201002",
                      "message": "cin is invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "propertyOwnership": {
                    "type": "string",
                    "enum": [
                      "Owned",
                      "Rented"
                    ],
                    "message": {
                      "return_code": "201002",
                      "message": "propertyOwnership is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  }
                },
                "message": {
                  "return_code": "201002",
                  "message": "Company Details are mandatory",
                  "CF_code": "CF300"
                }
              },
              "loanAmount": {
                "type": "integer",
                "minimum": 1,
                "message": {
                  "return_code": "201002",
                  "message": "loanAmount is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "purposeOfLoan": {
                "type": "string",
                "enum": [
                  "Business Expansion",
                  "Machinery/Equipment Purchase",
                  "Salaries and Wages",
                  "Marketing and Advertising",
                  "Technology Upgrades (Software/Hardware)",
                  "Hiring and Training",
                  "Property Renovation",
                  "Working Capital",
                  "Miscellaneous Expenses",
                  "Material Purchase",
                  "Operating Expenses",
                  "Other"
                ],
                "message": {
                  "return_code": "201002",
                  "message": "purposeOfLoan is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "tenure": {
                "type": "integer",
                "minimum": 1,
                "message": {
                  "return_code": "201002",
                  "message": "tenure is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "tenureFrequency": {
                "type": "string",
                "enum": [
                  "Monthly",
                  "Quarterly",
                  "Half-Yearly",
                  "Yearly"
                ],
                "message": {
                  "return_code": "201002",
                  "message": "tenureFrequency is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "roi": {
                "type": "number",
                "minimum": 0,
                "message": {
                  "return_code": "201002",
                  "message": "roi is mandatory or invalid",
                  "CF_code": "CF300"
                },
                "maximum": 100
              },
              "apr": {
                "type": "number",
                "minimum": 0,
                "message": {
                  "return_code": "201002",
                  "message": "apr is mandatory or invalid",
                  "CF_code": "CF300"
                },
                "maximum": 100
              },
              "emi": {
                "type": "number",
                "minimum": 1,
                "message": {
                  "return_code": "201002",
                  "message": "emi is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "processingFees": {
                "type": "number",
                "minimum": 0,
                "message": {
                  "return_code": "201002",
                  "message": "processingFees is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "insuranceCharges": {
                "type": "number",
                "minimum": 0,
                "message": {
                  "return_code": "201002",
                  "message": "insuranceCharges is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "documentCharges": {
                "type": "number",
                "minimum": 0,
                "message": {
                  "return_code": "201002",
                  "message": "documentCharges is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "eligibleLoanAmountMethod": {
                "type": "string",
                "minLength": 1,
                "message": {
                  "return_code": "201002",
                  "message": "eligibleLoanAmountMethod is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "bureauDetails": {
                "type": "object",
                "properties": {
                  "totalExistingObligations": {
                    "type": "number",
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "totalExistingObligations is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "overdueAmountInCCKCCGuarantorLoans": {
                    "type": "number",
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "overdueAmountInCCKCCGuarantorLoans is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "overdueAmountExceptCCAndKCC": {
                    "type": "number",
                    "minimum": 0,
                    "message": {
                      "return_code": "201002",
                      "message": "overdueAmountExceptCCAndKCC is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "nameOfBureau": {
                    "type": "string",
                    "message": {
                      "return_code": "201002",
                      "message": "nameOfBureau is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "maxDpdTradelineIn6Months": {
                    "type": "integer",
                    "message": {
                      "return_code": "201002",
                      "message": "maxDpdTradelineIn6Months is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "maxDpdTradelineIn12Months": {
                    "type": "integer",
                    "message": {
                      "return_code": "201002",
                      "message": "maxDpdTradelineIn12Months is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "restructuringInCcKccGoldLoanLast36Months": {
                    "type": "string",
                    "enum": [
                      "DBT",
                      "LSS",
                      "Written-Off",
                      "Settled",
                      "Restructured Loan",
                      "Post (WO) Settled",
                      "SUB",
                      "Suit Filed",
                      "Wilful Defaulter",
                      "Suit Filed and Wilful Default"
                    ]
                  },
                  "restructuringInCcLast36Months": {
                    "type": "string",
                    "enum": [
                      "DBT",
                      "LSS",
                      "Written-Off",
                      "Settled",
                      "Restructured Loan",
                      "Post (WO) Settled",
                      "SUB",
                      "Suit Filed",
                      "Wilful Defaulter",
                      "Suit Filed and Wilful Default"
                    ]
                  },
                  "restructuringInLast36Months": {
                    "type": "string",
                    "enum": [
                      "DBT",
                      "LSS",
                      "Written-Off",
                      "Settled",
                      "Restructured Loan",
                      "Post (WO) Settled",
                      "SUB",
                      "Suit Filed",
                      "Wilful Defaulter",
                      "Suit Filed and Wilful Default"
                    ]
                  }
                }
              },
              "coApplicants": {
                "type": "array",
                "maxItems": 5,
                "message": {
                  "return_code": "201004",
                  "message": "Only five co-applicants are allowed",
                  "CF_code": "CF300"
                },
                "items": {
                  "type": "object",
                  "properties": {
                    "firstName": {
                      "type": "string",
                      "minLength": 3,
                      "message": {
                        "return_code": "201002",
                        "message": "Customer name is required",
                        "CF_code": "CF300",
                        "pattern": "^[a-zA-Z\\s\\.\\']+$"
                      }
                    },
                    "dateOfBirth": {
                      "description": "dateOfBirth",
                      "type": "string",
                      "pattern": "^\\d{4}\\-(0?[1-9]|1[012])\\-(0?[1-9]|[12][0-9]|3[01])$",
                      "message": {
                        "return_code": "201002",
                        "message": "dateOfBirth is mandatory or invalid",
                        "CF_code": "CF300"
                      }
                    },
                    "gender": {
                      "type": "string",
                      "enum": [
                        "Male",
                        "Female",
                        "Other"
                      ],
                      "message": {
                        "return_code": "201002",
                        "message": "gender is mandatory or invalid",
                        "CF_code": "CF300"
                      }
                    },
                    "maritalStatus": {
                      "type": "string",
                      "enum": [
                        "Unmarried",
                        "Married",
                        "Divorced",
                        "Widowed"
                      ],
                      "message": {
                        "return_code": "201002",
                        "message": "maritalStatus is mandatory or invalid",
                        "CF_code": "CF300"
                      }
                    },
                    "relationship": {
                      "type": "string",
                      "message": {
                        "return_code": "201002",
                        "message": "relationship is invalid",
                        "CF_code": "CF300"
                      }
                    },
                    "mobileNumber": {
                      "type": "string",
                      "pattern": "^[0-9]\\d{9}$",
                      "minLength": 10,
                      "maxLength": 10,
                      "message": {
                        "return_code": "201002",
                        "message": "Communication Mobile Number is required in the correct format & length. It should be string",
                        "CF_code": "CF300",
                        "pattern": ""
                      }
                    },
                    "panNumber": {
                      "type": "string",
                      "pattern": "^[A-Z]{5}[0-9]{4}[A-Z]{1}$",
                      "message": {
                        "return_code": "201002",
                        "message": "Invalid PAN Number",
                        "CF_code": "CF300"
                      }
                    },
                    "aadhaarNumber": {
                      "type": "string",
                      "pattern": "^[0-9]{12}$",
                      "message": {
                        "return_code": "201002",
                        "message": "Invalid Aadhaar Number",
                        "CF_code": "CF300"
                      }
                    },
                    "permanentAddress": {
                      "type": "string",
                      "maxLength": 255,
                      "message": {
                        "return_code": "201002",
                        "message": "permanentAddress is mandatory or invalid",
                        "CF_code": "CF300"
                      }
                    },
                    "permanentCity": {
                      "type": "string",
                      "pattern": "^[a-zA-Z\\s]+$",
                      "message": {
                        "return_code": "201002",
                        "message": "permanentCity is mandatory or invalid",
                        "CF_code": "CF300"
                      }
                    },
                    "permanentState": {
                      "type": "string",
                      "message": {
                        "return_code": "201002",
                        "message": "permanentState is mandatory or invalid",
                        "CF_code": "CF300"
                      },
                      "enum": [
                        "Andhra Pradesh",
                        "Arunachal Pradesh",
                        "Assam",
                        "Bihar",
                        "Chhattisgarh",
                        "Goa",
                        "Gujarat",
                        "Haryana",
                        "Himachal Pradesh",
                        "Jharkhand",
                        "Karnataka",
                        "Kerala",
                        "Madhya Pradesh",
                        "Maharashtra",
                        "Manipur",
                        "Meghalaya",
                        "Mizoram",
                        "Nagaland",
                        "Odisha",
                        "Punjab",
                        "Rajasthan",
                        "Sikkim",
                        "Tamil Nadu",
                        "Telangana",
                        "Tripura",
                        "Uttar Pradesh",
                        "Uttarakhand",
                        "West Bengal",
                        "Andaman and Nicobar Islands",
                        "Chandigarh",
                        "Dadra and Nagar Haveli and Daman and Diu",
                        "Delhi",
                        "Jammu and Kashmir",
                        "Ladakh",
                        "Lakshadweep",
                        "Puducherry"
                      ]
                    },
                    "permanentPincode": {
                      "type": "string",
                      "pattern": "^[0-9]{6}$",
                      "message": {
                        "return_code": "201002",
                        "message": "Pincode must be 6 digits",
                        "CF_code": "CF300"
                      }
                    }
                  },
                  "required": [
                    "firstName",
                    "dateOfBirth",
                    "gender",
                    "maritalStatus",
                    "mobileNumber",
                    "panNumber",
                    "permanentAddress",
                    "permanentCity",
                    "permanentState",
                    "permanentPincode"
                  ]
                }
              }
            },
            "required": [
              "loanId",
              "firstName",
              "dateOfBirth",
              "gender",
              "maritalStatus",
              "mobileNumber",
              "panNumber",
              "nationality",
              "entityType",
              "addresses",
              "loanAmount",
              "purposeOfLoan",
              "tenure",
              "tenureFrequency",
              "roi",
              "apr",
              "emi",
              "companyDetails",
              "bankDetails",
              "bureauDetails",
              "eligibleLoanAmountMethod"
            ]
          }
        },
        "persistence": [
          {
            "operation": "query",
            "queryType": "insert",
            "table": "vendor_loans_data",
            "auto_id": "id",
            "values": {
              "partner_id": "$vendor_details.vendor_id",
              "application_id": "$request.loanId",
              "customer_name": "$request.firstName",
              "date_of_birth": "$request.dateOfBirth",
              "gender": "$request.gender",
              "marital_status": "$request.maritalStatus",
              "nationality": "$request.nationality",
              "mobile_number": "encrypt->$request.mobileNumber",
              "email_id": "encrypt->$request.personalEmailId",
              "pan_number": "encrypt->$request.panNumber",
              "aadhaar_number": "encrypt->$request.aadhaarNumber",
              "customer_category": "$request.entityType",
              "current_address": "$current_address.addressLine",
              "current_city": "$current_address.city",
              "current_district": "$current_address.district",
              "current_state": "$current_address.state",
              "current_pincode": "$current_address.pincode",
              "permanent_address": "$permanent_address.addressLine",
              "permanent_city": "$permanent_address.city",
              "permanent_district": "$permanent_address.district",
              "permanent_state": "$permanent_address.state",
              "permanent_pincode": "$permanent_address.pincode",
              "loan_amount": "$request.loanAmount",
              "purpose_of_loan": "$request.purposeOfLoan",
              "tenure": "$request.tenure",
              "tenure_frequency": "$request.tenureFrequency",
              "roi": "$request.roi",
              "apr": "$request.apr",
              "emi": "$request.emi",
              "processing_fees": "$request.processingFees",
              "insurance_charges": "$request.insuranceCharges",
              "document_charges": "$request.documentCharges",
              "eligible_loan_amount_method": "$request.eligibleLoanAmountMethod",
              "gst": "encrypt->$request.companyDetails.gst",
              "cin": "$request.companyDetails.cin",
              "created_at": "datetime.CUR_TIMESTAMP"
            }
          },
          {
            "operation": "query",
            "queryType": "insert",
            "table": "vendor_loans_company_details",
            "values": {
              "vendor_loan_id": "$vendor_loans_data_id",
              "application_id": "$request.loanId",
              "company_name": "$request.companyDetails.companyName",
              "company_address": "$request.companyDetails.companyAddress",
              "company_city": "$request.companyDetails.companyCity",
              "company_district": "$request.companyDetails.companyDistrict",
              "company_state": "$request.companyDetails.companyState",
              "company_pincode": "$request.companyDetails.companyPincode",
              "industry_type": "$request.companyDetails.industryType",
              "business_vintage": "$request.companyDetails.businessVintage",
              "udyam_number": "$request.companyDetails.udyamNumber",
              "annual_turnover": "$request.companyDetails.annualTurnover",
              "created_at": "datetime.CUR_TIMESTAMP"
            }
          },
          {
            "operation": "query",
            "queryType": "insert",
            "table": "vendor_loans_bank_details",
            "values": {
              "vendor_loan_id": "$vendor_loans_data_id",
              "application_id": "$request.loanId",
              "account_holder_name": "$request.bankDetails.accountHolderName",
              "account_number": "encrypt->$request.bankDetails.accountNumber",
              "account_type": "$request.bankDetails.accountType",
              "bank_name": "$request.bankDetails.bankName",
              "ifsc_code": "$request.bankDetails.ifscCode",
              "min_bank_transaction_in_month": "$request.bankDetails.minBankTransactionInMonth",
              "no_of_credit_transaction_in_month": "$request.bankDetails.noOfCreditTransactionInMonth",
              "no_of_debit_transaction_in_month": "$request.bankDetails.noOfDebitTransactionInMonth",
              "no_of_inward_transactions": "$request.bankDetails.noOfInwardTransactions",
              "no_of_cheque_bounces": "$request.bankDetails.noOfChequeBounces",
              "no_of_inward_cheque_returns": "$request.bankDetails.noOfInwardChequeReturns",
              "no_of_outward_cheque_returns": "$request.bankDetails.noOfOutwardChequeReturns",
              "max_98_cc_od_utilization": "$request.bankDetails.maxCcOdUtilization",
              "nach_return_in_last_3_months": "$request.bankDetails.nachReturnInLast3Months",
              "created_at": "datetime.CUR_TIMESTAMP"
            }
          },
          {
            "operation": "query",
            "queryType": "insert",
            "table": "vendor_loans_bureau_obligations",
            "values": {
              "vendor_loan_id": "$vendor_loans_data_id",
              "application_id": "$request.loanId",
              "total_existing_obligations": "$request.bureauDetails.totalExistingObligations",
              "overdue_amount_in_cc_kcc_guarantor_loans": "$request.bureauDetails.overdueAmountInCCKCCGuarantorLoans",
              "overdue_amount_except_cc_and_kcc": "$request.bureauDetails.overdueAmountExceptCCAndKCC",
              "name_of_bureau": "$request.bureauDetails.nameOfBureau",
              "max_dpd_tradeline_in_6_months": "$request.bureauDetails.maxDpdTradelineIn6Months",
              "max_dpd_tradeline_in_12_months": "$request.bureauDetails.maxDpdTradelineIn12Months",
              "restructuring_in_cc_kcc_gold_loan_last_36_months": "$request.bureauDetails.restructuringInCcKccGoldLoanLast36Months",
              "restructuring_in_cc_last_36_months": "$request.bureauDetails.restructuringInCcLast36Months",
              "restructuring_in_last_36_months": "$request.bureauDetails.restructuringInLast36Months",
              "created_at": "datetime.CUR_TIMESTAMP"
            }
          },
          {
            "operation": "query",
            "queryType": "insert",
            "table": "vendor_status_logs",
            "values": {
              "vendor_loan_id": "$vendor_loans_data_id",
              "status": "in-process",
              "remark": null,
              "visible_to_partner": 1,
              "created_at": "datetime.CUR_TIMESTAMP"
            }
          },
          {
            "operation": "query",
            "queryType": "insert",
            "table": "vendor_loans_application_data_logs",
            "values": {
              "vendor_loan_id": "$vendor_loans_data_id",
              "data": "application_data_logs->$request",
              "status": "in-process",
              "user_id": 107,
              "created_at": "datetime.CUR_TIMESTAMP"
            }
          }
        ],
        "responses": {
          "CF200": {
            "content": {
              "application/json": {
                "success": "true",
                "loanId": "$request.loanId",
                "vendorLoanId": "$vendor_loans_data_id",
                "request_id": "$request_id",
                "returnStatus": {
                  "returnCode": "000000",
                  "returnText": "Application successfully submitted"
                }
              },
              "status_code": 200
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id"
                }
              }
            ]
          },
          "CF300": {
            "content": {
              "application/json": {
                "request_id": "$request_id",
                "returnStatus": {
                  "returnCode": "$response.return_code",
                  "returnText": "$validation_error.message"
                }
              },
              "status_code": 400
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id"
                }
              }
            ]
          },
          "CF500": {
            "content": {
              "application/json": {
                "request_id": "$request_id",
                "returnStatus": {
                  "returnCode": "500000",
                  "returnText": "Internal Server Error"
                }
              },
              "status_code": 500
            }
          }
        }
      }
    },
    "/customerRest/customerSrv/updateApplication": {
      "post": {
        "tags": [
          "Vendor Update Application"
        ],
        "requestBody": {
          "content": {
            "type": "object",
            "properties": {
              "vendorLoanId": {
                "type": "string",
                "message": {
                  "return_code": "201002",
                  "message": "vendorLoanId is mandatory",
                  "CF_code": "CF300"
                }
              },
              "loanAmount": {
                "type": "number",
                "minimum": 1,
                "message": {
                  "return_code": "201002",
                  "message": "loanAmount is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "purposeOfLoan": {
                "type": "string",
                "enum": [
                  "Business Expansion",
                  "Machinery/Equipment Purchase",
                  "Salaries and Wages",
                  "Marketing and Advertising",
                  "Technology Upgrades (Software/Hardware)",
                  "Hiring and Training",
                  "Property Renovation",
                  "Working Capital",
                  "Miscellaneous Expenses",
                  "Material Purchase",
                  "Operating Expenses",
                  "Other"
                ],
                "message": {
                  "return_code": "201002",
                  "message": "purposeOfLoan is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "tenure": {
                "type": "integer",
                "minimum": 1,
                "message": {
                  "return_code": "201002",
                  "message": "tenure is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "tenureFrequency": {
                "type": "string",
                "enum": [
                  "Monthly",
                  "Quarterly",
                  "Half-Yearly",
                  "Yearly"
                ],
                "message": {
                  "return_code": "201002",
                  "message": "tenureFrequency is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "roi": {
                "type": "number",
                "minimum": 0,
                "maximum": 100,
                "message": {
                  "return_code": "201002",
                  "message": "roi is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "apr": {
                "type": "number",
                "minimum": 0,
                "maximum": 100,
                "message": {
                  "return_code": "201002",
                  "message": "apr is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "emi": {
                "type": "number",
                "minimum": 1,
                "message": {
                  "return_code": "201002",
                  "message": "emi is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "processingFees": {
                "type": "number",
                "minimum": 0,
                "message": {
                  "return_code": "201002",
                  "message": "processingFees is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "insuranceCharges": {
                "type": "number",
                "minimum": 0,
                "message": {
                  "return_code": "201002",
                  "message": "insuranceCharges is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "documentCharges": {
                "type": "number",
                "minimum": 0,
                "message": {
                  "return_code": "201002",
                  "message": "documentCharges is mandatory or invalid",
                  "CF_code": "CF300"
                }
              },
              "bankDetails": {
                "type": "object",
                "properties": {
                  "accountHolderName": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 150,
                    "message": {
                      "return_code": "201002",
                      "message": "Account Holder Name is mandatory",
                      "CF_code": "CF300"
                    }
                  },
                  "accountNumber": {
                    "type": "string",
                    "pattern": "^[0-9]{9,18}$",
                    "message": {
                      "return_code": "201002",
                      "message": "Invalid Account Number",
                      "CF_code": "CF300"
                    }
                  },
                  "accountType": {
                    "type": "string",
                    "enum": [
                      "Savings",
                      "Current",
                      "Cash Credit (CC)",
                      "Overdraft (OD)"
                    ],
                    "message": {
                      "return_code": "201002",
                      "message": "Invalid Account Type",
                      "CF_code": "CF300"
                    }
                  },
                  "bankName": {
                    "type": "string",
                    "message": {
                      "return_code": "201002",
                      "message": "bankName is mandatory or invalid",
                      "CF_code": "CF300"
                    }
                  },
                  "ifscCode": {
                    "type": "string",
                    "pattern": "^[A-Z]{4}0[A-Z0-9]{6}$",
                    "message": {
                      "return_code": "201002",
                      "message": "Invalid IFSC Code",
                      "CF_code": "CF300"
                    }
                  }
                }
              }
            },
            "required": [
              "vendorLoanId"
            ]
          }
        },
        "responses": {
          "CF200": {
            "content": {
              "application/json": {
                "status": "Success",
                "vendor_loan_id": "$request.vendorLoanId",
                "request_id": "$request_id",
                "message": "$update_remark.remark"
              },
              "status_code": 200
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id"
                }
              }
            ]
          },
          "CF300": {
            "content": {
              "application/json": {
                "status": "Failed",
                "vendor_loan_id": "$request.vendorLoanId",
                "request_id": "$request_id",
                "message": "$response.message"
              },
              "status_code": 400
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id"
                }
              }
            ]
          },
          "CF500": {
            "content": {
              "application/json": "null",
              "status_code": 500
            }
          }
        },
        "functions": {
          "init": [
            {
              "operation": "setData",
              "stateKey": "request_id",
              "value": "UUID"
            },
            {
              "operation": "query",
              "queryType": "insert",
              "table": "vendor_api_request",
              "stateKey": "vendor_api_request_id",
              "values": {
                "created_at": "datetime.CUR_TIMESTAMP",
                "vendor_id": "$vendor_details.vendor_id",
                "request": "json_dumps->$request"
              },
              "auto_id": "id"
            }
          ],
          "getIdByApplicationNo": [
            {
              "operation": "query",
              "name": "getidbyapplicationno",
              "queryType": "select",
              "table": "vendor_loans_data",
              "columns": [
                "id", "status", "loan_amount", "tenure", "purpose_of_loan"
              ],
              "limit": 1,
              "clause": {
                "where": [
                  "id"
                ],
                "queryParams": [
                  "$request.vendorLoanId"
                ]
              },
              "stateKey": "vendor_loan_detail"
            },
            {
              "conditions": [
                "$vendor_loan_detail.id",
                "isNotNull"
              ],
              "false": {
                "operation": "returnResponse",
                "return_code": "201003",
                "CF_code": "CF300",
                "message": "Loan Application Number does not exist"
              }
            }
          ],
          "validateStatusAndRemark": [
            {
              "conditions": [
                "$vendor_loan_detail.status",
                "in",
                "['in-process', 'approved', 'waiting for documents', 'pre-approved']"
              ],
              "false": {
                "operation": "returnResponse",
                "return_code": "201002",
                "CF_code": "CF300",
                "message": "Application can only be updated when status is in-process, pre-approved, approved or waiting for documents state"
              }
            },
            {
              "operation": "query",
              "queryType": "raw",
              "name": "generateUpdateRemark",
              "dbRaw": "SELECT IF(CONCAT_WS(\"\", NULLIF(NULLIF(%s, \"None\"), \"\"), NULLIF(NULLIF(%s, \"None\"), \"\"), NULLIF(NULLIF(%s, \"None\"), \"\")) <> \"\", CONCAT(\"Re-hit the BRE.Since the following details are update {\", CONCAT_WS(\", \", IF(NULLIF(NULLIF(%s, \"None\"), \"\") IS NOT NULL, \"Loan amount\", NULL), IF(NULLIF(NULLIF(%s, \"None\"), \"\") IS NOT NULL, \"Tenure\", NULL), IF(NULLIF(NULLIF(%s, \"None\"), \"\") IS NOT NULL, \"Purpose of the loan\", NULL)), \"} .\"), \"Application updated successfully.\") AS remark",
              "queryParams": [
                "$request.loanAmount",
                "$request.tenure",
                "$request.purposeOfLoan",
                "$request.loanAmount",
                "$request.tenure",
                "$request.purposeOfLoan"
              ],
              "stateKey": "update_remark"
            }
          ],
          "checkBRERehitNeeded": [
            {
              "operation": "setData",
              "stateKey": "bre_rehit_needed",
              "value": "checkBRERehitNeeded->$request,$vendor_loan_detail"
            },
            {
              "conditions": [
                "$bre_rehit_needed",
                "equals",
                "true"
              ],
              "true": {
                "operation": "setData",
                "stateKey": "newStatus",
                "value": "in-process"
              },
              "false": {
                "operation": "setData",
                "stateKey": "newStatus",
                "value": "$vendor_loan_detail.status"
              }
            }
          ]
        },
        "persistence": [
          {
            "operation": "query",
            "queryType": "update",
            "table": "vendor_loans_data",
            "clause": {
              "where": [
                "id"
              ],
              "queryParams": [
                "$vendor_loan_detail.id"
              ]
            },
            "values": {
              "loan_amount": "$request.loanAmount",
              "purpose_of_loan": "$request.purposeOfLoan",
              "tenure": "$request.tenure",
              "tenure_frequency": "$request.tenureFrequency",
              "roi": "$request.roi",
              "apr": "$request.apr",
              "emi": "$request.emi",
              "processing_fees": "$request.processingFees",
              "insurance_charges": "$request.insuranceCharges",
              "document_charges": "$request.documentCharges",
              "status": "$newStatus",
              "updated_at": "datetime.CUR_TIMESTAMP"
            }
          },
          {
            "operation": "query",
            "queryType": "update",
            "table": "vendor_loans_bank_details",
            "clause": {
              "where": [
                "vendor_loan_id"
              ],
              "queryParams": [
                "$request.vendorLoanId"
              ]
            },
            "values": {
              "account_holder_name": "$request.accountHolderName",
              "account_number": "$request.bankDetails.accountNumber",
              "account_type": "$request.bankDetails.accountType",
              "bank_name": "$request.bankDetails.bankName",
              "ifsc_code": "$request.bankDetails.ifscCode",
              "updated_at": "datetime.bankDetails.CUR_TIMESTAMP"
            }
          },
          {
            "conditions": [
              "$bre_rehit_needed",
              "equals",
              "true"
            ],
            "true": [
              {
                "operation": "query",
                "queryType": "insert",
                "table": "vendor_status_logs",
                "values": {
                  "vendor_loan_id": "$vendor_loan_detail.id",
                  "status": "in-process",
                  "remark": "$update_remark.remark",
                  "visible_to_partner": 1,
                  "created_at": "datetime.CUR_TIMESTAMP"
                }
              }
            ]
          }
        ]
      }
    },
    "/customerRest/customerSrv/runbre": {
      "post": {
        "tags": [
          "Run BRE"
        ],
        "requestBody": {
          "content": {
            "type": "object",
            "properties": {
              "vendorLoanId": {
                "type": "string",
                "message": {
                  "return_code": "201002",
                  "message": "vendorLoanId is mandatory",
                  "CF_code": "CF300"
                }
              }
            },
            "required": [
              "vendorLoanId"
            ]
          }
        },
        "responses": {
          "CF200": {
            "content": {
              "status_code": 200,
              "application/json": {
                "vendorLoanId": "$request.vendorLoanId",
                "status": "$bre_result.status"
              }
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id"
                }
              }
            ]
          },
          "CF300": {
            "content": {
              "application/json": {
                "returnStatus": {
                  "returnCode": "$response.return_code",
                  "returnText": "$response.message"
                }
              },
              "status_code": 400
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id"
                }
              }
            ]
          }
        },
        "functions": {
          "init": [
            {
              "operation": "setData",
              "stateKey": "request_id",
              "value": "UUID"
            },
            {
              "operation": "query",
              "queryType": "insert",
              "table": "vendor_api_request",
              "stateKey": "vendor_api_request_id",
              "values": {
                "created_at": "datetime.CUR_TIMESTAMP",
                "vendor_id": "$vendor_details.vendor_id",
                "request": "json_dumps->$request"
              },
              "auto_id": "id"
            }
          ],
          "getIdByApplicationNo": [
            {
              "operation": "query",
              "name": "getidbyapplicationno",
              "queryType": "select",
              "table": "vendor_loans_data",
              "columns": [
                "id", "status"
              ],
              "limit": 1,
              "clause": {
                "where": [
                  "id"
                ],
                "queryParams": [
                  "$request.vendorLoanId"
                ]
              },
              "stateKey": "vendor_loan_id"
            },
            {
              "conditions": [
                "$vendor_loan_id.id",
                "isNotNull"
              ],
              "false": {
                "operation": "returnResponse",
                "return_code": "201003",
                "CF_code": "CF300",
                "message": "Loan Application Number does not exist"
              }
            }
          ],
          "dataValidations": [
            {
              "operation": "setData",
              "value": "checkPreSanctionedDocumentsAvailable->$vendor_loan_id.id",
              "stateKey": "pre_sanctioned_documents_available"
            },
            {
              "conditions":[
                "$vendor_loan_id.status",
                "in",
                "['in-process']"
              ],
              "false": {
                "operation": "returnResponse",
                "return_code": "201002",
                "CF_code": "CF300",
                "message": "BRE can only be run when status is In-Process & Approved state"
              },
              "true": [
                {
                  "conditions": [
                    "$pre_sanctioned_documents_available",
                    "equals",
                    "true"
                  ],
                  "false": {
                    "operation": "returnResponse",
                    "return_code": "201002",
                    "CF_code": "CF300",
                    "message": "BRE cannot be run as pre-sanctioned documents are not available"
                  }
                }
              ]
            }
          ],
          "executeBre": [
            {
              "operation": "concat",
              "values": [
                "{'cmd':'command:colendingBRE','con':'jobs','param':{'vendor_loan_id':",
                "$request.vendorLoanId",
                "},'job_handler':'App\\\\Helpers\\\\CmdHelper@runCommand'}"
              ],
              "stateKey": "breQueuePayload"
            }
          ]
        },
        "persistence": [
          {
            "queryType": "insert",
            "table": "queue_log",
            "values": {
              "uid": "null",
              "status": "pen",
              "exchange": "job_exch",
              "route_key": "exch_rout_key_job",
              "job_handler": "App\\Helpers\\CmdHelper@runCommand",
              "input": "json_dumps->$breQueuePayload",
              "attempt_count": "0",
              "cmd": "command:AutoDecision",
              "created_at": "datetime.CUR_TIMESTAMP",
              "application_id": "$application_id",
              "updated_at": "datetime.CUR_TIMESTAMP"
            }
          }
        ]
      }
    },
    "/customerRest/documentSrv/uploadDocument": {
      "post": {
        "tags": [
          "Document Upload"
        ],
        "requestBody": {
          "content": {
            "type": "object",
            "properties": {
              "vendorLoanId": {
                "type": "string",
                "minLength": 1,
                "message": {
                  "return_code": "201002",
                  "message": "vendorLoanId is required",
                  "CF_code": "CF300",
                  "pattern": ""
                }
              },
              "applicantType": {
                "type": "number",
                "enum": [
                  1,
                  2.1,
                  2.2,
                  2.3,
                  2.4,
                  2.5
                ],
                "message": {
                  "return_code": "201002",
                  "message": "Please provide valid applicant type",
                  "CF_code": "CF300",
                  "pattern": ""
                }
              },
              "fileName": {
                "type": [
                  "string"
                ],
                "enum": [
                  "pan",
                  "form60",
                  "aadhar",
                  "video_PD",
                  "vkyc_report",
                  "partnership_deed",
                  "registration_proof",
                  "customer_selfie",
                  "business_photos",
                  "bureau_report",
                  "signed_loan_agreement",
                  "UDC",
                  "NACH",
                  "pennydrop_verification",
                  "bank_statement",
                  "udhyam_certificate",
                  "udyog_aadhar",
                  "MSME_certificate",
                  "gumasta",
                  "GST_certificate",
                  "POR",
                  "ITR",
                  "labor_certificate",
                  "house_utility_bill",
                  "business_utility_bill",
                  "ownership_declaration",
                  "house_tax_received",
                  "water_bill"
                ],
                "minLength": 1,
                "message": {
                  "return_code": "201002",
                  "message": "File name is required in the correct format",
                  "CF_code": "CF300",
                  "pattern": ""
                }
              },
              "docPath": {
                "type": "string",
                "minLength": 1,
                "message": {
                  "return_code": "201002",
                  "message": "Document path is required",
                  "CF_code": "CF300",
                  "pattern": ""
                }
              }
            },
            "required": [
              "vendorLoanId",
              "applicantType",
              "fileName",
              "docPath"
            ]
          },
          "rules": {
            "data": []
          }
        },
        "responses": {
          "CF300": {
            "content": {
              "application/json": {
                "request_id": "$request_id",
                "returnStatus": {
                  "returnCode": "$response.return_code",
                  "returnText": "$response.message"
                }
              },
              "status_code": 400
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id",
                  "updated_at": "datetime.CUR_TIMESTAMP"
                }
              }
            ]
          },
          "CF200": {
            "content": {
              "application/json": {
                "request_id": "$request_id",
                "returnStatus": {
                  "returnCode": "000000",
                  "returnText": "Document uploaded successfully"
                }
              },
              "status_code": 200
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id",
                  "updated_at": "datetime.CUR_TIMESTAMP"
                }
              }
            ]
          }
        },
        "functions": {
          "init": [
            {
              "operation": "setData",
              "stateKey": "request_id",
              "value": "UUID"
            },
            {
              "operation": "query",
              "queryType": "insert",
              "table": "vendor_api_request",
              "values": {
                "created_at": "datetime.CUR_TIMESTAMP",
                "vendor_id": "$merchant_details.id",
                "request": "json_dumps->$request"
              },
              "auto_id": "id"
            }
          ],
          "getIdByApplicationNo": [
            {
              "operation": "query",
              "queryType": "select",
              "table": "vendor_loans_data",
              "columns": [
                "id", "status", "application_id"
              ],
              "limit": 1,
              "clause": {
                "where": [
                  "id"
                ],
                "queryParams": [
                  "$request.vendorLoanId"
                ]
              },
              "stateKey": "vendor_loan_id"
            },
            {
              "conditions": [
                "$vendor_loan_id.id",
                "isNotNull"
              ],
              "false": {
                "operation": "returnResponse",
                "return_code": "201003",
                "CF_code": "CF300",
                "message": "Loan Application Number does not exist"
              }
            }
          ],
          "documentIdentification": [
            {
              "operation": "setData",
              "stateKey": "document_stage",
              "value": "setDocumentStage->$request.fileName"
            },
            {
              "conditions": [
                "$document_stage",
                "equals",
                "pre_sanctioned"
              ],
              "true": [
                {
                  "conditions": [
                    "$vendor_loan_id.status",
                    "in",
                    "['in-process', 'waiting for documents']"
                  ],
                  "false": {
                    "operation": "returnResponse",
                    "return_code": "201002",
                    "CF_code": "CF300",
                    "message": "Pre-sanctioned documents can only be uploaded for in-process and approved applications"
                  }
                }
              ]
            },
            {
              "conditions": [
                "$document_stage",
                "equals",
                "post_sanctioned"
              ],
              "true": [
                {
                  "conditions": [
                    "$vendor_loan_id.status",
                    "in",
                    "['approved','disbursement checklist done']"
                  ],
                  "false": {
                    "operation": "returnResponse",
                    "return_code": "201002",
                    "CF_code": "CF300",
                    "message": "Post-sanctioned documents can only be uploaded for approved and disbursement checklist done applications"
                  }
                }
              ]
            }
          ],
          "fileNameCreation": [
            {
              "operation": "setData",
              "stateKey": "file_name_prefix",
              "value": "setFileName->$request.applicantType"
            },
            {
              "operation": "setData",
              "stateKey": "applicant_type",
              "value": "setApplicantType->$request.applicantType"
            },
            {
              "operation": "concat",
              "stateKey": "final_file_name",
              "values": [
                "$file_name_prefix",
                "_",
                "$request.fileName"
              ]
            }
          ],
          "fetchPartnerId": [
            {
              "operation": "query",
              "queryType": "select",
              "table": "vendor",
              "columns": [
                "partner_id"
              ],
              "limit": 1,
              "clause": {
                "where": [
                  "name",
                  "type"
                ],
                "logicalOperator": "AND",
                "queryParams": [
                  "$merchant_details.merchant_name",
                  "partner"
                ]
              },
              "stateKey": "partner_id"
            }
          ],
          "validateUpload": [
            {
              "operation": "query",
              "queryType": "select",
              "table": "blacksoil_documents",
              "columns": [
                "id", "document_status"
              ],
              "clause": {
                "where": [
                  "vendor_loan_id",
                  "product_id",
                  "applicant_type",
                  "file_name"
                ],
                "logicalOperator": "AND",
                "queryParams": [
                  "$request.vendorLoanId",
                  "$partner_id",
                  "$applicant_type",
                  "$final_file_name"
                ],
                "limit": 1,
                "ordering": {
                  "sorting": "DESC",
                  "column": "created_at"
                }
              },
              "stateKey": "existing_document"
            },
            {
              "conditions": [
                "$existing_document.id",
                "isNotNull"
              ],
              "true": [
                {
                  "conditions": [
                    "$existing_document.document_status",
                    "equals",
                    "0"
                  ],
                  "false": {
                    "operation": "returnResponse",
                    "return_code": "201002",
                    "CF_code": "CF300",
                    "message": "Document already exists for this applicant type"
                  }
                }
              ]
            }
          ],
          "downloadAndSaveDocument": [
            {
              "operation": "setData",
              "stateKey": "document_save_result",
              "value": "DownloadAndSaveDocument->$vendor_loan_id.application_id,$request.applicantType,$final_file_name,$request.docPath"
            },
            {
              "conditions": [
                "$document_save_result.status",
                "equals",
                "doc_size_exceeded"
              ],
              "true": {
                "operation": "returnResponse",
                "return_code": "201002",
                "CF_code": "CF300",
                "message": "Document exceeds the 20 MiB size limit"
              }
            },
            {
              "conditions": [
                "$document_save_result.status",
                "in",
                "['doc_download_empty','doc_download_fail']"
              ],
              "true": {
                "operation": "returnResponse",
                "return_code": "201002",
                "CF_code": "CF300",
                "message": "Unable to download document"
              }
            }
          ],
          "moveToDCD": [
            {
              "conditions": [
                "$document_stage",
                "equals",
                "post_sanctioned"
              ],
              "true": [
                {
                  "operation": "setData",
                  "value": "checkPostSanctionedDocumentsAvailable->$vendor_loan_id.id",
                  "stateKey": "eligibleForDCD"
                }
              ]
            }
          ]
        },
        "persistence": [
          {
            "operation": "query",
            "queryType": "insert",
            "table": "blacksoil_documents",
            "values": {
              "vendor_loan_id": "$request.vendorLoanId",
              "loan_id": "$vendor_loan_id.application_id",
              "product_id": "$partner_id",
              "applicant_type": "$request.applicantType",
              "file_name": "$final_file_name",
              "document_code": "upper->$request.fileName",
              "file_path": "$document_save_result.s3_path",
              "document_status": null,
              "created_at": "datetime.CUR_TIMESTAMP"
            }
          },
          {
             "conditions": [
              "$eligibleForDCD",
              "equals",
              "true"
            ],
            "true": {
              "operation": "query",
              "queryType": "update",
              "table": "vendor_loans_data",
              "clause": {
                "where": [
                  "id"
                ],
                "queryParams": [
                  "$request.vendorLoanId"
                ]
              },
              "values": {
                "status": "disbursement checklist done"
              }
            }
          },
          {
            "conditions": [
              "$eligibleForDCD",
              "equals",
              "true"
            ],
            "true": {
              "operation": "query",
              "queryType": "insert",
              "table": "vendor_status_logs",
              "values": {
                "vendor_loan_id": "$request.vendorLoanId",
                "status": "disbursement checklist done",
                "remark": null,
                "visible_to_partner": 1,
                "created_at": "datetime.CUR_TIMESTAMP"
              }
            }
          }
        ]
      }
    },
    "/customerRest/documentSrv/submitDisbursementDetails": {
      "post": {
        "tags": [
          "Submit Disbursement Details"
        ],
        "functions": {
          "init": [
            {
              "operation": "setData",
              "stateKey": "request_id",
              "value": "UUID"
            },
            {
              "operation": "query",
              "queryType": "insert",
              "table": "vendor_api_request",
              "stateKey": "vendor_api_request_id",
              "values": {
                "created_at": "datetime.CUR_TIMESTAMP",
                "vendor_id": "$merchant_details.id",
                "request": "json_dumps->$request"
              },
              "auto_id": "id"
            }
          ],
          "validateLoanAndStatus": [
            {
              "operation": "query",
              "name": "getvendorloandata",
              "queryType": "select",
              "table": "vendor_loans_data",
              "columns": [
                "id",
                "status"
              ],
              "limit": 1,
              "clause": {
                "where": [
                  "id"
                ],
                "queryParams": [
                  "$request.vendorLoanId"
                ]
              },
              "stateKey": "vendor_loan"
            },
            {
              "conditions": [
                "$vendor_loan.id",
                "isNotNull"
              ],
              "false": {
                "operation": "returnResponse",
                "return_code": "201003",
                "CF_code": "CF300",
                "message": "Loan Application Number does not exist"
              }
            },
            {
              "conditions": [
                "$vendor_loan.status",
                "equals",
                "ready for disbursement"
              ],
              "false": {
                "operation": "returnResponse",
                "return_code": "201002",
                "CF_code": "CF300",
                "message": "Disbursement details can only be submitted when the application is Ready for Disbursement"
              }
            },
            {
              "operation": "query",
              "queryType": "raw",
              "name": "getActiveDisbursement",
              "dbRaw": "SELECT id, status FROM vendor_disbursement_details WHERE vendor_loan_id = %s AND UPPER(TRIM(COALESCE(status, \"\"))) <> \"REJECTED\" ORDER BY id DESC LIMIT 1",
              "queryParams": [
                "$vendor_loan.id"
              ],
              "stateKey": "active_disbursement"
            },
            {
              "conditions": [
                "$active_disbursement.id",
                "isNotNull"
              ],
              "true": {
                "operation": "returnResponse",
                "return_code": "201004",
                "CF_code": "CF300",
                "message": "Disbursement details already received and under review"
              }
            }
          ]
        },
        "requestBody": {
          "content": {
            "type": "object",
            "properties": {
              "vendorLoanId": {
                "type": "string",
                "minLength": 1,
                "message": {
                  "return_code": "201002",
                  "message": "vendorLoanId is required",
                  "CF_code": "CF300"
                }
              },
              "loanId": {
                "type": "string",
                "minLength": 1,
                "message": {
                  "return_code": "201002",
                  "message": "Loan_id is required",
                  "CF_code": "CF300"
                }
              },
              "utrNumber": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-zA-Z0-9]+$",
                "message": {
                  "return_code": "201002",
                  "message": "UTR Number is required in the correct format",
                  "CF_code": "CF300"
                }
              },
              "disbursementDate": {
                "type": "string",
                "pattern": "^\\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$",
                "message": {
                  "return_code": "201002",
                  "message": "Disbursement date is required in YYYY-MM-DD format",
                  "CF_code": "CF300"
                }
              },
              "sanctionAmount": {
                "type": "integer",
                "message": {
                  "return_code": "201002",
                  "message": "Sanction Amount is required and must be an integer",
                  "CF_code": "CF300"
                }
              }
            },
            "required": [
              "vendorLoanId",
              "loanId",
              "utrNumber",
              "disbursementDate",
              "sanctionAmount"
            ]
          }
        },
        "persistence": [
          {
            "operation": "query",
            "queryType": "insert",
            "table": "vendor_disbursement_details",
            "values": {
              "vendor_loan_id": "$vendor_loan.id",
              "utr_number": "$request.utrNumber",
              "disbursement_date": "$request.disbursementDate",
              "amount": "$request.sanctionAmount",
              "status": "pending",
              "created_at": "datetime.CUR_TIMESTAMP",
              "updated_at": "datetime.CUR_TIMESTAMP"
            }
          }
        ],
        "responses": {
          "CF200": {
            "content": {
              "application/json": {
                "success": true,
                "loan_id": "$request.loanId",
                "vendor_loan_id": "$request.vendorLoanId",
                "request_id": "$request_id",
                "message": "Disbursement details under review"
              },
              "status_code": 200
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id",
                  "updated_at": "datetime.CUR_TIMESTAMP"
                }
              }
            ]
          },
          "CF300": {
            "content": {
              "application/json": {
                "success": false,
                "loan_id": "$request.loanId",
                "vendor_loan_id": "$request.vendorLoanId",
                "request_id": "$request_id",
                "message": "$response.message"
              },
              "status_code": 400
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id",
                  "updated_at": "datetime.CUR_TIMESTAMP"
                }
              }
            ]
          },
          "CF500": {
            "content": {
              "application/json": "null",
              "status_code": 500
            }
          }
        }
      }
    },
    "/customerRest/documentSrv/fetchLoanStatus": {
      "post": {
        "tags": [
          "Vendor check application status"
        ],
        "requestBody": {
          "content": {
            "type": "object",
            "properties": {
              "vendorLoanId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              }
            }
          }
        },
        "responses": {
          "CF200": {
            "content": {
              "application/json": {
                "request_id": "$request_id",
                "status": "$vendor_loan_data.status",
                "vendorLoanId": "$vendor_loan_data.id",
                "loan_id": "$vendor_loan_data.application_id"
              },
              "status_code": 200
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id",
                  "updated_at": "datetime.CUR_TIMESTAMP"
                }
              }
            ]
          },
          "CF300": {
            "content": {
              "application/json": {
                "application_id": "$request.vendorLoanId",
                "loan_id": "$vendor_loan_data.application_id",
                "message": "$response.message",
                "request_id": "$request_id"
              },
              "status_code": 400
            },
            "actions": [
              {
                "operation": "query",
                "queryType": "update",
                "table": "vendor_api_request",
                "clause": {
                  "where": [
                    "id"
                  ],
                  "queryParams": [
                    "$vendor_api_request_id"
                  ]
                },
                "values": {
                  "response": "json_dumps->$response",
                  "request_id": "$request_id",
                  "updated_at": "datetime.CUR_TIMESTAMP"
                }
              }
            ]
          },
          "CF500": {
            "content": {
              "application/json": "null",
              "status_code": 500
            }
          }
        },
        "functions": {
          "init": [
            {
              "operation": "setData",
              "stateKey": "request_id",
              "value": "UUID"
            },
            {
              "operation": "query",
              "queryType": "insert",
              "table": "vendor_api_request",
              "values": {
                "created_at": "datetime.CUR_TIMESTAMP",
                "vendor_id": "$merchant_details.id",
                "request": "json_dumps->$request"
              },
              "auto_id": "id"
            }
          ],
          "getIdByApplicationNo": [
            {
              "operation": "query",
              "queryType": "select",
              "table": "vendor_loans_data",
              "columns": [
                "id", "status", "application_id"
              ],
              "limit": 1,
              "clause": {
                "where": [
                  "id"
                ],
                "queryParams": [
                  "$request.vendorLoanId"
                ]
              },
              "stateKey": "vendor_loan_id"
            },
            {
              "conditions": [
                "$vendor_loan_id.id",
                "isNotNull"
              ],
              "false": {
                "operation": "returnResponse",
                "return_code": "201003",
                "CF_code": "CF300",
                "message": "Loan Application Number does not exist"
              }
            }
          ],
          "fetchStatusDetails": [
            {
              "operation": "query",
              "queryType": "raw",
              "name": "getVendorLoanStatus",
              "dbRaw": "SELECT vld.id, vld.application_id, COALESCE(vld.vendor_loan_id, \"\") AS loan_id, vld.status, COALESCE(NULLIF((SELECT vsl.remark FROM vendor_status_logs vsl WHERE vsl.vendor_loan_id = vld.id AND (vsl.visible_to_partner = 1 OR vsl.visible_to_partner IS NULL) ORDER BY vsl.created_at DESC, vsl.id DESC LIMIT 1), \"\"), vld.status) AS message FROM vendor_loans_data vld WHERE vld.application_id = COALESCE(NULLIF(%s, \"\"), %s) ORDER BY vld.id DESC LIMIT 1",
              "queryParams": [
                "$vendor_loan_id.application_id",
                "$vendor_loan_id.applicationId"
              ],
              "stateKey": "vendor_loan_data"
            }
          ]
        }
      }
    }
  }
}
