swagger: "2.0"
info:
  description: "This API allows to interact with the amazing TechUBank"
  version: "2.0.0"
  title: "techubank_api-client"
  termsOfService: ""
  contact:
    email: "techubank@bbva.com"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "localhost:3000"
basePath: "/v2"
schemes:
  - "http"
  - "https"
security:
  - APIKeyHeader: []
paths:
  /user:
    post:
      tags:
        - "User"
      summary: "Create a new user"
      description: "Create a new TechU Bank's user"
      operationId: "createUser"
      produces:
        - "application/json"
      parameters:
        - in: "body"        
          name: "user"
          required: true
          schema:
            $ref: "#/definitions/User"      
      responses:
        200:
          description: "User created successfully"
          schema:
            $ref: "#/definitions/User"      
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges to create a user"
          schema:
            $ref: "#/definitions/ErrorMessage"          
    get:
      tags:
        - "User"   
      summary: "Get all users"
      description: "Get basic info from TechU Bank's users"
      operationId: "getAllUsers"
      produces:
        - "application/json"
      parameters:
        - in: query
          name: filter
          description: "Get main user's info matching the filter"
          type: string
      responses:
        200:
          description: "Get and array of users"
          schema:
            $ref: "#/definitions/ArrayOfUsers"
  /user/{username}:
    get:
      tags:
        - "User"   
      summary: "Get user by user name"
      description: "Get user by user name"
      operationId: "getUserByName"
      produces:
        - "application/json"
      parameters:
        - in: "path"
          name: "username"
          description: "The name that needs to be fetched."
          required: true
          type: string
      responses:
        200:
          description: "successful operation"
          schema:
            $ref: "#/definitions/User"
        400:
          description: "Invalid username supplied"
        404:
          description: "User not found"
    put:
      tags:
        - "User"   
      summary: "Updated user"
      description: "This can only be done by the logged user or admin"
      operationId: "updateUser"
      produces:
        - "application/json"
      parameters:
        - in: "path"
          name: "username"
          description: "The name that needs to be fetched."
          required: true
          type: string
        - in: "body"        
          name: "user"
          required: true
          schema:
            $ref: "#/definitions/User"      
      responses:
        200:
          description: "User updated successfully"
          schema:
            $ref: "#/definitions/User"      
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges to create a user"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "User not found"
          schema:
            $ref: "#/definitions/ErrorMessage"                        
    delete:
      tags:
        - "User"   
      summary: "Delete user"
      description: "This can only be done by the logged user or admin."
      operationId: "deleteUser"
      produces:
        - "application/json"
      parameters:
      - in: "path"
        name: "username"
        description: "The name that needs to be deleted"
        required: true
        type: "string"
      responses:
        200:
          description: "User deleted successfully"
          type: string        
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges to create a user"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "User not found"
          schema:
            $ref: "#/definitions/ErrorMessage"  
  /user/{username}/changePassword:
    post:
      tags:
        - "User"   
      summary: "Change user's password"
      description: "Change user's password"
      operationId: "changePassword"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: "body"        
          name: "user"
          required: true
          schema:
            $ref: "#/definitions/UserResetPassword"   
      responses:
        200:
          description: "User updated successfully"
          schema:
            $ref: "#/definitions/UserBasicInfo"      
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges to create a user"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "User not found"
          schema:
            $ref: "#/definitions/ErrorMessage"   
  /user/{username}/login:
    post:
      tags:
        - "User"   
      summary: "Logs user into the system"
      description: "Login"
      operationId: "loginUser"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: "body"
          name: "body"
          description: "User login object"
          required: true
          schema:
            $ref: "#/definitions/UserLogin"
      responses:
        200:
          description: "successful operation"
        400:
          description: "Invalid username/password supplied"
  /user/{username}/logout:
    post:
      tags:
        - "User"
      summary: "Logout user"
      description: "Logout user"
      operationId: "logoutUser"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
      responses:
        200:
          description: "User logged out"
        403:
          description: "You don't have privileges to logout that session"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Session not found"
          schema:
            $ref: "#/definitions/ErrorMessage"  
  /user/{username}/globalposition:
    get:
      tags:
        - "User"    
      summary: "Get user's global position"
      description: "Get user's global position"
      operationId: "getGlobalPosition"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
      responses:
        200:
          description: "User's global position"
          schema:
              $ref: "#/definitions/UserGlobalPosition"           
        403:
          description: "You don't have privileges to get that global position"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Global Position not found"
          schema:
            $ref: "#/definitions/ErrorMessage"         
  /products/{username}:
    get:
      tags:
        - "Products"
      summary: "Get user products"
      description: "Get user products"
      operationId: "getUserProducts"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
      responses:
        200:
          description: "Get user's products"
          schema:
            $ref: "#/definitions/ArrayOfUserProducts"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"  
  /products/{username}/account:
    get:
      tags:
        - "Products - Account"
      summary: "Get all user's products of type account"
      description: "Get all user's products of type account"
      operationId: "getAllUserAccounts"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
      responses:
        200:
          description: "User's accounts"
          schema:
              $ref: "#/definitions/ArrayOfUserAccounts"           
        403:
          description: "You don't have privileges to get user's accounts"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "not found"
          schema:
            $ref: "#/definitions/ErrorMessage"         
    post:
      tags:
        - "Products - Account"
      summary: "Create user's product of type account"
      description: "Create user's product of type account"
      operationId: "createAccountProduct"
      produces:
      - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: "body"
          name: "account_info"
          description: "Logout user from the system"
          required: true
          schema:
            $ref: "#/definitions/Account"
      responses:
        200:
          description: "Products - Account created"
          schema:
            $ref: "#/definitions/Account"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"    
  /products/{username}/account/{accountId}:
    get:
      tags:
      - "Products - Account"    
      summary: "Get user's account info"
      description: "Get user's account detail information"
      operationId: "getAccountDetail"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true          
      responses:
        200:
          description: "Transfer done"
          schema:
            $ref: "#/definitions/ArrayOfTransfers"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"        
    put:
      tags:
      - "Products - Account"    
      summary: "Update user's account info"
      description: "Update user's account info"
      operationId: "updateAccountInfo"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true           
      responses:
        200:
          description: "Transfer done"
          schema:
            $ref: "#/definitions/ArrayOfTransfers"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"        
    delete:
      tags:
      - "Products - Account"    
      summary: "Delete user's account"
      description: "Delete user's account"
      operationId: "deleteAccount"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true           
      responses:
        200:
          description: "Transfer done"
          schema:
            $ref: "#/definitions/ArrayOfTransfers"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"        
  /products/{username}/account/{accountId}/transfer:
    post:
      tags:
      - "Products - Account - Transfer"
      summary: "Create a transfer between two accounts"
      description: "Create a transfer between two accounts"
      operationId: "makeTransfer"
      produces:
      - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true
        - in: "body"
          name: "transfer_request"
          description: "Transfer info"
          required: true
          schema:
            $ref: "#/definitions/TransferRequest"
      responses:
        200:
          description: "Transfer done"
          schema:
            $ref: "#/definitions/TransferDetail"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"       
    get:
      tags:
        - "Products - Account - Transfer"    
      summary: "Get last transfers"
      description: "Get last transfers"
      operationId: "getAllTransfers"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true          
      responses:
        200:
          description: "Transfer done"
          schema:
            $ref: "#/definitions/ArrayOfTransfers"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"     
  /products/{username}/account/{accountId}/transfer/{transferId}:
    get:
      tags:
      - "Products - Account - Transfer"    
      summary: "Get detail info for a specific transfer"
      description: "Get detail info for a specific transfer"    
      operationId: "getTransferDetail"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true      
        - in: path
          name: transferId
          type: string
          required: true
      responses:
        200:
          description: "Transfer done"
          schema:
            $ref: "#/definitions/ArrayOfTransfers"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"          
    delete:
      tags:
      - "Products - Account - Transfer"    
      summary: "Reject a transfer"
      description: "Reject a transfer"     
      operationId: "rejectTransfer"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true      
        - in: path
          name: transferId
          type: string
          required: true
      responses:
        200:
          description: "Transfer rejected"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"         
  /products/{username}/account/{accountId}/movements:
    get:
      tags:
      - "Products - Account - Movements"    
      summary: "Get user's account movements"
      description: "Get user movements. If there is no filter it get last month movements"
      operationId: "getAccountMovements"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true           
      responses:
        200:
          description: "Array of movements"
          schema:
            $ref: "#/definitions/ArrayOfMovements"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"        
  /products/{username}/account/{accountId}/movements/{movementId}:
    get:
      tags:
      - "Products - Account - Movements"    
      summary: "Get detail user's movement info"
      description: "Get detail user movement info"
      operationId: "getAccountMovementDetail"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true 
        - in: path
          name: movementId
          type: string
          required: true                     
      responses:
        200:
          description: "Transfer done"
          schema:
            $ref: "#/definitions/ArrayOfTransfers"
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage" 
        404:
          description: "Holders not found"
          schema:
            $ref: "#/definitions/ErrorMessage"        
    delete:
      tags:
        - "Products - Account - Movements"    
      summary: "Reject a movement"
      description: "Reject a movement"
      operationId: "rejectAccountMovement"
      produces:
        - "application/json"
      parameters:
        - in: path
          name: username
          type: string
          required: true
        - in: path
          name: accountId
          type: string
          required: true 
        - in: path
          name: movementId
          type: string
          required: true  
      responses:
        200:
          description: "Movement rejected"
          schema:
            type: string
        400:
          description: "Error in the request body"
          schema:
            $ref: "#/definitions/ErrorMessage"          
        403:
          description: "You don't have privileges"
          schema:
            $ref: "#/definitions/ErrorMessage"      
securityDefinitions:
  APIKeyHeader:
    type: "apiKey"
    name: "X-API-Key"
    in: "header"
externalDocs:
  description: "Find out more about Swagger"
  url: "http://swagger.io"
definitions:
  ArrayOfUserProducts:
    type: "array"
    items:
      $ref: "#/definitions/UserProduct"
  ArrayOfUserAccounts:
    type: "array"
    items:
      $ref: "#/definitions/Account"      
  ArrayOfUsers:
    type: "array"    
    items:
      $ref: "#/definitions/UserBasicInfo"      
  ArrayOfTransfers:
    type: "array"
    items:
      $ref: "#/definitions/TransferDetail"
  ArrayOfMovements:
    type: "array"
    items:
      $ref: "#/definitions/Movement"        
  UserProduct:
    type: "object"
    required: 
      - product_type
    properties:
      product_type:
        type: "string"
        enum: ["Products - Account", "CARD"]
      product_value:
        type: "object"
  TransferDetail:
    type: "object"
    properties:
      id: 
        type: "integer"
      status:
        type: "string"
        enum: ["DONE", "REJECTED", "PENDING", "CANCELED"]
      comments:
        type: "string"
  TransferRequest:
    type: "object"
    properties:
      from:
        type: "string"
        example: "xxxx-xxxx-xxxx-xxxx"
      to:
        type: "string"
        example: "xxxx-xxxx-xxxx-xxxx"  
      requestor:
        type: "object"
        $ref: "#/definitions/UserBasicInfo"
      destination:
        type: "string"
        example: "Literal name"
      transfer_date:
        type: "string"
      description:
        type: "string"
      amount:
        type: "double"
  Movement:
    type: "object"
    properties:
      origin:
        type: "string"
      destination:
        type: "string"
  UserGlobalPosition:
    type: "object"
    properties:
      userInfo:
        type: "object"
        $ref: "#/definitions/UserBasicInfo"
      products:
        type: "array"
        items:
          $ref: "#/definitions/UserProduct"
  User:
    type: "object"
    properties:
      username:
        type: "string"
        example: "my-nickname"
      firstName:
        type: "string"
        example: "Name"
      lastName:
        type: "string"
        example: "Surname"
      email:
        type: "string"
        example: "user@bbva.com"
      password:
        type: "string"
        example: "secret"
      phone:
        type: "string"
        example: "+34 666-66-66-66"
      userStatus:
        type: "string"
        enum: ["ACTIVE", "BLOCKED"]
  UserBasicInfo:
    type: "object"
    properties:
      username:
        type: "string"
      email:
        type: "string"
      userStatus:
        type: "string"
        enum: ["ACTIVE", "BLOCKED"]
  UserLogin:
    type: "object"
    properties:
      username:
        type: "string"
      password:
        type: "string"
  UserResetPassword:
    type: "object"
    properties:
      username:
        type: "string"
      oldpassword:
        type: "string"
      newpassword:
        type: "string"
      renewpassword:
        type: "string"
  UserLogout:
    type: "object"
    properties:
      username:
        type: "string"
  Card:
    type: "object"
    properties:
      cardNumber:
        type: "string"
      title:
        type: "string"
      holder:
        type: "object"
        $ref: "#/definitions/UserBasicInfo"
      co_holder:
        type: "object"
        $ref: "#/definitions/UserBasicInfo"
      card_type:
        type: "string"
        enum: ["Debit", "Prepaid"]
      creation_date:
        type: "string"
      status:
        type: "string"
        enum: ["ACTIVE", "BLOCKED", "NEGATIVE"]
      description:
        type: "string"
  Account:
    type: "object"
    properties:
      product_type:
        type: "string"
      accountNumber:
        type: "string"
      title:
        type: "string"
      holder:
        type: "object"
        $ref: "#/definitions/UserBasicInfo"
      co_holder:
        type: "object"
        $ref: "#/definitions/UserBasicInfo"
      account_type:
        type: "string"
        enum: ["Checking account", "Savings account", "Individual Retirement Account (IRAs)"]
      creation_date:
        type: "string"
      status:
        type: "string"
        enum: ["ACTIVE", "BLOCKED", "NEGATIVE"]
      description:
        type: "string"
  ErrorMessage:
    type: "object"
    properties:
      internal_code:
        type: "string"
      message:
        type: "string"
 