openapi: 3.0.0
info:
  version: '2.0'
  title: 'Service System'
  description: 'Service System'

servers:
  - url: http://powercooling.serveo.net/api/v2

security:
  - Authorization: []

tags:
  - name: companies
  - name: clients
  - name: locations
  - name: tradesmen
  - name: vendors
  - name: trades
  - name: work_orders
  - name: invoices
  - name: inbound-invoices
  - name: purchase_orders
  - name: payments
  - name: bill_payments
  - name: ledger_accounts
  - name: items
  - name: user-session
  - name: user-registration

paths:
  /companies:
    get:
      tags:
        - companies
      summary: List All companies
      operationId: ListCompanies
      parameters:
        - in: query
          name: skip_existing_clients
          description: "Skip Existing Clients"
          schema:
            type: boolean
        - in: query
          name: skip_existing_vendors
          description: "Skip Existing Vendors"
          schema:
            type: boolean
        - $ref: '#/components/parameters/companyIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  'companies:':
                    type: array
                    items:
                      $ref: '#/components/schemas/Company'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
  /clients:
    get:
      tags:
        - clients
      summary: List Clients
      description: ''
      operationId: ListClients
      parameters:
        - $ref: '#/components/parameters/clientIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  'clients:':
                    type: array
                    items:
                      $ref: '#/components/schemas/Client'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
    post:
      tags:
        - clients
      summary: Add Client
      description: Add Client
      operationId: 'create-client'
      parameters:
        - $ref: '#/components/parameters/clientIncludeParam'
      requestBody:
        $ref: '#/components/requestBodies/Client'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Client'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                properties:
                  errors:
                    type: object

  /clients/{id}:
    get:
      tags:
        - clients
      summary: Show Client
      description: ''
      operationId: ShowClient
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/clientIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Client'
        '404':
          description: Record Not Found
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
    patch:
      tags:
        - clients
      summary: Update Client
      description: ''
      operationId: UpdateClient
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/clientIncludeParam'
      requestBody:
        $ref: '#/components/requestBodies/Client'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Client'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                properties:
                  errors:
                    type: object
  /tradesmen:
    get:
      tags:
        - tradesmen
      summary: List Tradesmen
      description: ''
      operationId: ListTradesmen
      parameters:
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  tradesmen:
                    type: array
                    items:
                      $ref: '#/components/schemas/Tradesman'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
    post:
      tags:
        - tradesmen
      summary: Add Tradesman
      description: ''
      operationId: CreateTradesman
      requestBody:
        $ref: '#/components/requestBodies/Tradesman'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  tradesman:
                    $ref: '#/components/schemas/Tradesman'
  /tradesmen/{id}:
    get:
      tags:
        - tradesmen
      summary: Show Tradesman
      description: ''
      operationId: showTradesman
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  tradesman:
                    $ref: '#/components/schemas/Tradesman'
    patch:
      tags:
        - tradesmen
      summary: Update Tradesman
      description: ''
      operationId: updateTradesman
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
      requestBody:
        $ref: '#/components/requestBodies/Tradesman'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  tradesman:
                    $ref: '#/components/schemas/Tradesman'

  /vendors:
    get:
      tags:
        - vendors
      summary: List Vendors
      description: ''
      operationId: ListVendors
      parameters:
        - $ref: '#/components/parameters/vendorIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  vendors:
                    type: array
                    items:
                      $ref: '#/components/schemas/Vendor'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
    post:
      tags:
        - vendors
      summary: Add Vendor
      description: Add Vendor
      operationId: addVendor
      parameters:
        - $ref: '#/components/parameters/vendorIncludeParam'
      requestBody:
        $ref: '#/components/requestBodies/Vendor'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Company'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                properties:
                  errors:
                    type: object

  /vendors/{id}:
    get:
      tags:
        - vendors
      summary: Show Vendor
      description: ''
      operationId: showVendor
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/vendorIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Vendor'
        '404':
          description: Record Not Found
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
    patch:
      tags:
        - vendors
      summary: Update Vendor
      description: ''
      operationId: updateVendor
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/vendorIncludeParam'
      requestBody:
        $ref: '#/components/requestBodies/Vendor'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Vendor'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                properties:
                  errors:
                    type: object
  /locations:
    get:
      tags:
        - locations
      summary: List Locations
      description: ''
      operationId: ListLocations
      parameters:
        - $ref: '#/components/parameters/locationIncludeParam'
        - $ref: '#/components/parameters/locationRansack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  locations:
                    type: array
                    items:
                      $ref: '#/components/schemas/Location'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
    post:
      tags:
        - locations
      summary: Create Location
      description: ''
      operationId: CreateLocation
      requestBody:
        $ref: '#/components/requestBodies/CreateLocation'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  location:
                    $ref: '#/components/schemas/Location'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'

  /locations/{id}:
    get:
      tags:
        - locations
      summary: Show Location
      description: ''
      operationId: ShowLocation
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/locationIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  location:
                    $ref: '#/components/schemas/Location'
    patch:
      tags:
        - locations
      summary: Update Location
      description: ''
      operationId: UpdateLocation
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/locationIncludeParam'
      requestBody:
        $ref: '#/components/requestBodies/UpdateLocation'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  location:
                    $ref: '#/components/schemas/Location'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
  /trades:
    get:
      tags:
        - trades
      summary: List Trades
      description: ''
      operationId: ListTrades
      parameters:
        - $ref: '#/components/parameters/TradeIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  'trades:':
                    type: array
                    items:
                      $ref: '#/components/schemas/Trade'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
    post:
      tags:
        - trades
      summary: Add a new Trade
      description: ''
      operationId: CreateTrade
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  trade:
                    $ref: '#/components/schemas/Trade'
      requestBody:
        $ref: '#/components/requestBodies/CreateTrade'

  /trades/{id}:
    get:
      tags:
        - trades
      summary: Show Trade
      description: ''
      operationId: ShowTrade
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/TradeIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  trade:
                    $ref: '#/components/schemas/Trade'
    patch:
      tags:
        - trades
      summary: Update a Trade
      description: ''
      operationId: UpdateTrade
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/TradeIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  trade:
                    $ref: '#/components/schemas/Trade'
      requestBody:
        $ref: '#/components/requestBodies/CreateTrade'

  /work_orders:
    get:
      tags:
        - work_orders
      summary: List WorkOrders
      description: ''
      operationId: ListWorkOrders
      parameters:
        - $ref: '#/components/parameters/WorkOrderIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  'work_orders:':
                    type: array
                    items:
                      $ref: '#/components/schemas/WorkOrder'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
    post:
      tags:
        - work_orders
      summary: Add a new WorkOrder
      description: ''
      operationId: CreateWorkOrder
      parameters:
        - $ref: '#/components/parameters/WorkOrderIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  work_order:
                    $ref: '#/components/schemas/WorkOrder'
      requestBody:
        $ref: '#/components/requestBodies/CreateWorkOrder'

  /work_orders/{id}:
    get:
      tags:
        - work_orders
      summary: Show WorkOrder
      description: ''
      operationId: ShowWorkOrder
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/WorkOrderIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  work_order:
                    $ref: '#/components/schemas/WorkOrder'

    delete:
      tags:
        - work_orders
      summary: delete WorkOrder
      operationId: DeleteWorkOrder
      description: 'On WorkOrder deletion dependent trips will get deleted. Select the force parameter as true, if you are willing to delete the workorder even services are exists.'
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - in: query
          name: force
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: successful operation

    patch:
      tags:
        - work_orders
      summary: Update a WorkOrder
      description: ''
      operationId: UpdateWorkOrder
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/WorkOrderIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  work_order:
                    $ref: '#/components/schemas/WorkOrder'
      requestBody:
        $ref: '#/components/requestBodies/UpdateWorkOrder'

  /work_orders/{work_order_id}/trips/{id}:
    delete:
      tags:
        - workorder-trips
      summary: delete Trip
      operationId: DeleteTrip
      description: 'Select the force parameter as true, if you are willing to delete the trips even services are exists.'
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - in: path
          name: work_order_id
          required: true
          schema:
            type: string
        - in: query
          name: force
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: successful operation
  /invoices:
    get:
      tags:
        - invoices
      summary: List Invoices
      description: ''
      operationId: ListInvoices
      parameters:
        - $ref: '#/components/parameters/InvoiceIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  invoices:
                    type: array
                    items:
                      $ref: '#/components/schemas/Invoice'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'

    post:
      tags:
        - invoices
      summary: Add a new Invoice
      description: ''
      operationId: CreateInvoice
      parameters:
        - $ref: '#/components/parameters/InvoiceIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  invoice:
                    $ref: '#/components/schemas/Invoice'
      requestBody:
        $ref: '#/components/requestBodies/CreateInvoice'

  /invoices/{id}:
    get:
      tags:
        - invoices
      summary: Show Invoice
      description: ''
      operationId: ShowInvoice
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/InvoiceIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  invoice:
                    $ref: '#/components/schemas/Invoice'

    patch:
      tags:
        - invoices
      summary: Update an Invoice
      description: ''
      operationId: UpdateInvoice
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/InvoiceIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  invoice:
                    $ref: '#/components/schemas/Invoice'
      requestBody:
        $ref: '#/components/requestBodies/UpdateInvoice'

  /inbound_invoices:
    get:
      tags:
        - inbound-invoices
      summary: List Inbound Invoices
      description: ''
      operationId: ListInboundInvoices
      parameters:
        - $ref: '#/components/parameters/InboundInvoiceIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  inbound_invoices:
                    type: array
                    items:
                      $ref: '#/components/schemas/Invoice'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'

  /inbound_invoices/{id}:
    patch:
      tags:
        - inbound-invoices
      summary: Update an Inbound Invoice
      description: ''
      operationId: UpdateInboundInvoice
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/InboundInvoiceIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  invoice:
                    $ref: '#/components/schemas/Invoice'
      requestBody:
        $ref: '#/components/requestBodies/UpdateInboundInvoice'

  /purchase_orders:
    get:
      tags:
        - purchase_orders
      summary: List Purchase Orders
      description: ''
      operationId: ListPurchaseOrders
      parameters:
        - $ref: '#/components/parameters/PurchaseOrderIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  purchase_orders:
                    type: array
                    items:
                      $ref: '#/components/schemas/PurchaseOrder'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'

    post:
      tags:
        - purchase_orders
      summary: Add a new Purchase Order
      description: ''
      operationId: CreatePurchaseOrder
      parameters:
        - $ref: '#/components/parameters/PurchaseOrderIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  purchase_order:
                    $ref: '#/components/schemas/PurchaseOrder'
      requestBody:
        $ref: '#/components/requestBodies/CreatePurchaseOrder'

  /purchase_orders/{id}:
    get:
      tags:
        - purchase_orders
      summary: Show PurchaseOrders
      description: ''
      operationId: ShowPurchaseOrder
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/PurchaseOrderIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  purchase_order:
                    $ref: '#/components/schemas/PurchaseOrder'

    patch:
      tags:
        - purchase_orders
      summary: Update an Purchase Order
      description: ''
      operationId: UpdatePurchaseOrder
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/PurchaseOrderIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  purchase_order:
                    $ref: '#/components/schemas/PurchaseOrder'
      requestBody:
        $ref: '#/components/requestBodies/UpdatePurchaseOrder'

  /payments:
    get:
      tags:
        - payments
      summary: List Payments
      description: ''
      operationId: ListPayments
      parameters:
        - $ref: '#/components/parameters/PaymentIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  payments:
                    type: array
                    items:
                      $ref: '#/components/schemas/Payment'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
    post:
      tags:
        - payments
      summary: Add a new Payment
      description: ''
      operationId: CreatePayment
      parameters:
        - $ref: '#/components/parameters/PaymentIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  payment:
                    $ref: '#/components/schemas/Payment'
      requestBody:
        $ref: '#/components/requestBodies/CreatePayment'

  /payments/{id}:
    get:
      tags:
        - payments
      summary: Show Payments
      description: ''
      operationId: ShowPayment
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/PaymentIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  payment:
                    $ref: '#/components/schemas/Payment'

    patch:
      tags:
        - payments
      summary: Update Payment
      description: ''
      operationId: UpdatePayment
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/PaymentIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  payment:
                    $ref: '#/components/schemas/Payment'
      requestBody:
        $ref: '#/components/requestBodies/UpdatePayment'

  /bill_payments:
    get:
      tags:
        - bill_payments
      summary: List Bill Payments
      description: ''
      operationId: ListBillPayments
      parameters:
        - $ref: '#/components/parameters/BillPaymentIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  bill_payments:
                    type: array
                    items:
                      $ref: '#/components/schemas/BillPayment'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'

    post:
      tags:
        - bill_payments
      summary: Add a new Bill Payment
      description: ''
      operationId: CreateBillPayment
      parameters:
        - $ref: '#/components/parameters/BillPaymentIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  bill_payment:
                    $ref: '#/components/schemas/BillPayment'
      requestBody:
        $ref: '#/components/requestBodies/BillPayment'

  /bill_payments/{id}:
    get:
      tags:
        - bill_payments
      summary: Show Bill Payments
      description: ''
      operationId: ShowBillPayment
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/BillPaymentIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  bill_payment:
                    $ref: '#/components/schemas/BillPayment'

    patch:
      tags:
        - bill_payments
      summary: Update Bill Payment
      description: ''
      operationId: UpdateBillPayment
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/BillPaymentIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  bill_payment:
                    $ref: '#/components/schemas/BillPayment'
      requestBody:
        $ref: '#/components/requestBodies/BillPayment'

  /ledger_accounts:
    get:
      tags:
        - ledger_accounts
      summary: Ledger Account
      description: ''
      operationId: List Ledger Accounts
      parameters:
        - $ref: '#/components/parameters/LedgerAccountIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  ledger_accounts:
                    type: array
                    items:
                      $ref: '#/components/schemas/LedgerAccount'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'
    post:
      tags:
        - ledger_accounts
      summary: Add a new Ledger Account
      description: ''
      operationId: CreateLedgerAccount
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  ledger_account:
                    $ref: '#/components/schemas/LedgerAccount'
      requestBody:
        $ref: '#/components/requestBodies/LedgerAccount'

  /ledger_accounts/{id}:
    get:
      tags:
        - ledger_accounts
      summary: Show Ledger Accounts
      description: ''
      operationId: ShowLedgerAccounts
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/LedgerAccountIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  ledger_account:
                    $ref: '#/components/schemas/LedgerAccount'

    patch:
      tags:
        - ledger_accounts
      summary: Update Ledger Account
      description: ''
      operationId: UpdateLedgerAccount
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/LedgerAccountIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  payment:
                    $ref: '#/components/schemas/LedgerAccount'
      requestBody:
        $ref: '#/components/requestBodies/LedgerAccount'

  /item_types:
    get:
      tags:
        - items
      summary: Item Types
      description: ''
      operationId: List Item Types
      parameters:
        - $ref: '#/components/parameters/ItemTypeIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  item_types:
                    type: array
                    items:
                      $ref: '#/components/schemas/ItemType'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'

    post:
      tags:
        - items
      summary: Add a new Item Type
      description: ''
      operationId: CreateItemType
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  item_types:
                    $ref: '#/components/schemas/ItemType'
      requestBody:
        $ref: '#/components/requestBodies/ItemType'

  /item_types/{id}:
    get:
      tags:
        - items
      summary: Show Item Types
      description: ''
      operationId: ShowItemTypes
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/ItemTypeIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  item_types:
                    $ref: '#/components/schemas/ItemType'

    patch:
      tags:
        - items
      summary: Update Item Type
      description: ''
      operationId: UpdateItemType
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/ItemTypeIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  item_types:
                    $ref: '#/components/schemas/UpdateItemType'
      requestBody:
        $ref: '#/components/requestBodies/UpdateItemType'

    delete:
      tags:
        - items
      summary: delete Item Type
      operationId: DeleteItemType
      description: ''
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - in: query
          name: force
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: successful operation

  /items:
    get:
      tags:
        - items
      summary: Items
      operationId: List Items
      parameters:
        - $ref: '#/components/parameters/ItemIncludeParam'
        - $ref: '#/components/parameters/ransack'
        - $ref: '#/components/parameters/pageParam'
        - $ref: '#/components/parameters/perPageParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/Item'
                  meta:
                    $ref: '#/components/schemas/PaginationInfo'

    post:
      tags:
        - items
      summary: Add a new Item
      description: ''
      operationId: CreateItem
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    $ref: '#/components/schemas/Item'
      requestBody:
        $ref: '#/components/requestBodies/Item'

  /items/{id}:
    get:
      tags:
        - items
      summary: Show Item
      description: ''
      operationId: ShowItem
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/ItemIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    $ref: '#/components/schemas/Item'

    patch:
      tags:
        - items
      summary: Update Item
      description: ''
      operationId: UpdateItem
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
        - $ref: '#/components/parameters/ItemIncludeParam'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  item_types:
                    $ref: '#/components/schemas/Item'
      requestBody:
        $ref: '#/components/requestBodies/UpdateItem'

    delete:
      tags:
        - items
      summary: delete Item
      operationId: DeleteItem
      description: ''
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
        - in: query
          name: force
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: successful operation

  '/users/session':
    post:
      tags:
        - user-session
      summary: SignIn
      description: ''
      operationId: LogIn
      security: []
      responses:
        '200':
          description: successful operation
          content:
            application/vnd.serviceautomation.v2:
              schema:
                type: object
                properties:
                  id:
                    type: integer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - user
              properties:
                user:
                  type: object
                  required:
                    - email
                    - password
                  properties:
                    email:
                      type: string
                    password:
                      type: string

        required: true

  /users/registration:
    post:
      tags:
        - user-registration
      summary: SignUp
      description: ''
      operationId: SignUp
      security: []
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  user:
                    $ref: '#/components/schemas/User'
      requestBody:
        $ref: '#/components/requestBodies/UserRegistration'

components:
  parameters:
    ransack: &ransack
      in: query
      name: q
      description: |
        **Example:**
        `
        {
          "<attribute_name>_cont": "<text to be searched>",
          "s": "<attribute_name> <sort_order(asc/desc)>"
        }
        `
        - search/sort by name and sort

        Reffer [Ransack Search Documentation](https://github.com/activerecord-hackery/ransack/wiki/Basic-Searching)

      schema:
        type: object

      style: deepObject
      explode: true
    locationRansack:
      <<: *ransack
      description: |
        **Example:**
        `
        {
          "<attribute_name>_cont": "<text to be searched>",
          "s": "<attribute_name> <sort_order(asc/desc)>"
        }
        `

        - search/sort by name and sort

        **Filter locations for a client with Id#10**
        `
          {"company_id_eq": 10}
        `

        Reffer [Ransack Search Documentation](https://github.com/activerecord-hackery/ransack/wiki/Basic-Searching)
    pageParam:
      in: query
      name: page
      required: false
      schema:
        type: integer
      description: Page Number - Default is 1
    perPageParam:
      in: query
      name: per_page
      required: false
      schema:
        type: integer
        maximum: 100
      description: No of records Per Page - Default is 25
    includeParam: &includeParam
      in: query
      name: include
      description: |
        **Include nested objects in result**
      style: form
      explode: false
      schema: &includeParamSchema
        type: array
        items:
          type: string
    companyIncludeParam:
      <<: *includeParam
      schema:
        <<: *includeParamSchema
        items:
          enum:
            - logo
            - contacts
            - qbd_customer_connection
            - qbd_vendor_connection
    clientIncludeParam:
      <<: *includeParam
      schema:
        <<: *includeParamSchema
        items:
          enum:
            - logo
            - contacts
            - qbd_customer_connection
    vendorIncludeParam:
      <<: *includeParam
      schema:
        <<: *includeParamSchema
        items:
          enum:
            - logo
            - contacts
            - qbd_vendor_connection
    locationIncludeParam:
      <<: *includeParam
      schema:
        <<: *includeParamSchema
        items:
          enum:
            - address
            - billing_address
            - image
            - contacts
            - qbd_connection
            - company
            - "company/qbd_customer_connection"
    TradeIncludeParam:
      in: query
      name: include
      description: |
        **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - "sub_trades"
            - "parent_trade"

    WorkOrderIncludeParam:
      in: query
      name: include
      description: |
        **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - "trips"
            - "trips/ivr"
            - "trips/tradesmen_trips"
            - "trips/external_connections"
            - "trips/trade"
            - "company"
            - "company/logo"
            - "company/contacts"
            - "locations"
            - "locations/address"
            - "locations/billing_address"
            - "locations/image"
            - "locations/contacts"
            - "work_order_notes"
    InvoiceIncludeParam:
      in: query
      name: include
      description: |
        **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - company
            - locations
            - qbd_connection
            - "company/qbd_customer_connection"
            - "invoice_items/item/item_type"
            - "invoice_items/item/department"
            - "invoice_items/item/qbd_connection"

    PurchaseOrderIncludeParam:
      in: query
      name: include
      description: |
         **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - purchase_order_assignment
            - qbd_connection
            - vendor
            - "vendor/qbd_vendor_connection"

    InboundInvoiceIncludeParam:
      in: query
      name: include
      description: |
         **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - company
            - locations
            - qbd_bill_connection
            - "company/qbd_customer_connection"

    PaymentIncludeParam:
      in: query
      name: include
      description: |
         **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - invoice_payments
            - "invoice_payments/invoice"
            - "invoice_payments/invoice/qbd_connection"
            - qbd_connection
            - client
            - "client/qbd_customer_connection"

    BillPaymentIncludeParam:
      in: query
      name: include
      description: |
         **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - ledger_account
            - "ledger_account/qbd_connection"
            - bill_payment_items
            - "bill_payment_items/invoice"
            - "bill_payment_items/invoice/qbd_connection"
            - qbd_connection
            - vendor
            - "vendor/qbd_vendor_connection"

    LedgerAccountIncludeParam:
      in: query
      name: include
      description: |
         **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - qbd_connection

    ItemTypeIncludeParam:
      in: query
      name: include
      description: |
         **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - qbd_connection

    ItemIncludeParam:
      in: query
      name: include
      description: |
         **Include nested objects in result**
      style: form
      explode: false
      schema:
        <<: *includeParamSchema
        items:
          type: string
          enum:
            - item_type
            - department
            - qbd_connection
            - income_account
            - "income_account/qbd_connection"
            - expense_account
            - "expense_account/qbd_connection"
            - asset_account
            - "asset_account/qbd_connection"

  securitySchemes:
    Authorization:            # arbitrary name for the security scheme
      type: http
      scheme: bearer
      bearerFormat: JWT
  ############################ RequestBodies Start ###################
  requestBodies:
    UserRegistration:
      description: User Registration Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              user:
                type: object
                required:
                  - first_name
                  - last_name
                  - email
                  - password
                  - password_confirmation
                properties:
                  first_name:
                    type: string
                  last_name:
                    type: string
                  email:
                    type: string
                    format: email
                  password:
                    type: string
                    format: password
                    minimum: 6
                  password_confirmation:
                    type: string
                    format: password
                    minimum: 6
    Tradesman:
      description: Tradesman Object
      required: true
      content:
        application/json:
          schema:
            type: object
            required:
              - first_name
              - last_name
              - ftc_user_name
            properties:
              first_name:
                type: string
              last_name:
                type: string
              email:
                type: string
              ftc_user_name:
                type: string
              phone:
                type: string
    Client:
      description: Client Object / Company Id
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              client:
                type: object
                required:
                  - name
                properties:
                  name:
                    type: string
                  email:
                    type: string
                  phone:
                    type: string
                  fax:
                    type: string
                  contacts_attributes:
                    type: array
                    items:
                      $ref: "#/components/schemas/Contact"
                  qbd_customer_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    Vendor:
      description: Vendor Object / Company Id
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              vendor:
                type: object
                required:
                  - name
                properties:
                  name:
                    type: string
                  email:
                    type: string
                  phone:
                    type: string
                  fax:
                    type: string
                  contacts_attributes:
                    type: array
                    items:
                      $ref: "#/components/schemas/Contact"
                  qbd_vendor_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    CreateLocation:
      description: Location Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              location:
                type: object
                required:
                  - name
                  - company_id
                  - address_attributes
                properties:
                  name:
                    type: string
                  company_id:
                    type: integer
                  tax_exempt:
                    type: boolean
                    default: false
                  address_attributes:
                    $ref: "#/components/schemas/Address"
                  billing_address_attributes:
                    $ref: "#/components/schemas/Address"
                  contacts_attributes:
                    type: array
                    items:
                      $ref: "#/components/schemas/Contact"
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    UpdateLocation:
      description: Location Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              location:
                type: object
                required:
                  - name
                  - address_attributes
                properties:
                  name:
                    type: string
                  tax_exempt:
                    type: boolean
                    default: false
                  address_attributes:
                    $ref: "#/components/schemas/Address"
                  billing_address_attributes:
                    $ref: "#/components/schemas/Address"
                  contacts_attributes:
                    type: array
                    items:
                      $ref: "#/components/schemas/Contact"
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    CreateTrade:
      description: Trade Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              trade:
                type: object
                required:
                  - name
                properties:
                  name:
                    type: string
                  description:
                    type: string
                  sic_code:
                    type: string
                  authorization_number:
                    type: string
                  licenses:
                    type: string
                  state:
                    type: string
                  no_equipment:
                    type: boolean
                    default: false
                  parent_id:
                    type: integer
                    description: 'Optional - Trade#Id of parent when adding SubTrade'

    CreateWorkOrder:
      description: WorkOrder Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              work_order:
                type: object
                required:
                  - work_order_type
                  - location_ids
                  - priority
                  - problem_type
                properties:
                  work_order_type:
                    type: string
                    enum:
                      - Time and Materials
                      - Non Billable
                      - Proposal
                      - Purchase Order
                  priority:
                    type: string
                    enum:
                      - Emergency
                      - Non Emergency
                  problem_type:
                    type: string
                    enum:
                      - Repair
                  service_system:
                    type: string
                  location_ids:
                    type: array
                    items:
                      type: integer
                  instructions:
                    type: string
                  work_order_name:
                    type: string
                  dispatch_now:
                    type: boolean
                    default: true
                  no_dispatch_reason:
                    type: string
                    description: required when dispatch_now is not true
                  work_order_notes_attributes:
                    type: array
                    items:
                      $ref: '#/components/schemas/WorkOrderNote'
                  trips_attributes:
                    type: array
                    items:
                      type: object
                      properties:
                        start_date:
                          type: string
                          format: date-time
                        end_date:
                          type: string
                          format: date-time
                        nte:
                          type: number
                          format: currency
                        description:
                          type: string
                          format: text
                          description: "Description per trip. If empty will be taken from WorkOrder#insturctions (Only for New Trip)"
                        external_status:
                          type: string
                        contractor_id:
                          type: integer
                          description: 'Vendor#id'
                        trade_id:
                          type: integer
                        equipments:
                          type: array
                          items:
                            type: string
                        priority:
                          $ref: '#/components/schemas/TripPriority'
                        ivr_attributes:
                          type: object
                          properties:
                            phone_type:
                              type: string
                            phone_no:
                              type: string
                            pin:
                              type: string
                            instructions:
                              type: string
                        tradesmen_trips_attributes:
                          type: array
                          items:
                            type: object
                            required:
                              - tradesman_id
                            properties:
                              start_date:
                                type: string
                                format: date-time
                              end_date:
                                type: string
                                format: date-time
                              tradesman_id:
                                type: integer
                        external_connections_attributes:
                          type: array
                          items:
                            $ref: '#/components/schemas/ExternalConnection'

    UpdateWorkOrder:
      description: WorkOrder Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              work_order:
                type: object
                required:
                  - location_ids
                  - priority
                  - problem_type
                properties:
                  priority:
                    type: string
                    enum:
                      - Emergency
                      - Non Emergency
                  problem_type:
                    type: string
                    enum:
                      - Repair
                  location_ids:
                    type: array
                    items:
                      type: integer
                  instructions:
                    type: string
                  work_order_name:
                    type: string
                  dispatch_now:
                    type: boolean
                    default: true
                  no_dispatch_reason:
                    type: string
                    description: required when dispatch_now is not true
                  work_order_notes_attributes:
                    type: array
                    items:
                      $ref: '#/components/schemas/WorkOrderNote'
                  trips_attributes:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: integer
                          description: required when updating
                        start_date:
                          type: string
                          format: date-time
                        end_date:
                          type: string
                          format: date-time
                        nte:
                          type: number
                          format: currency
                        description:
                          type: string
                          format: text
                          description: "Description per trip. If empty will be taken from WorkOrder#insturctions"
                        external_status:
                          type: string
                        contractor_id:
                          type: integer
                          description: 'Vendor#id'
                        trade_id:
                          type: integer
                        equipments:
                          type: array
                          items:
                            type: string
                        priority:
                          $ref: '#/components/schemas/TripPriority'
                        ivr_attributes:
                          type: object
                          properties:
                            phone_type:
                              type: string
                            phone_no:
                              type: string
                            pin:
                              type: string
                            instructions:
                              type: string
                        tradesmen_trips_attributes:
                          type: array
                          items:
                            type: object
                            required:
                              - tradesman_id
                            properties:
                              id:
                                type: integer
                                description: required when updating
                              start_date:
                                type: string
                                format: date-time
                              end_date:
                                type: string
                                format: date-time
                              tradesman_id:
                                type: integer
                        external_connections_attributes:
                          type: array
                          items:
                            $ref: '#/components/schemas/ExternalConnection'

    CreateInvoice:
      description: Invoice Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              invoice:
                type: object
                required:
                  - company_id
                  - location_ids
                properties:
                  company_id:
                    type: integer
                  location_ids:
                    type: array
                    items:
                      type: integer
                  resource_type:
                    type: string
                    default: null
                    enum:
                      - WorkOrder
                  resource_id:
                    type: integer
                    default: null
                  status:
                    type: string
                    default: draft
                    enum:
                      - draft
                      - sent
                      - paid
                      - partially_paid
                  terms:
                    type: string
                    description: Sets the due date
                    enum:
                      - Due On Receipt
                      - Net 15
                      - Net 30
                      - Net 45
                  date_of_issue:
                    type: string
                    format: date-time
                  due_date:
                    type: string
                    format: date-time
                  discount:
                    type: number
                    format: float
                    description: In Dollars
                  billing_address:
                    type: string
                  invoice_message:
                    type: string
                  statement_memo:
                    type: string
                  custom_invoice_number:
                    type: string
                  to_emails:
                    type: array
                    items:
                      type: string
                      format: email
                  invoice_items_attributes:
                    type: array
                    items:
                      type: object
                      required:
                        - item_name
                        - price
                        - quantity
                      properties:
                        item_id:
                          type: integer
                          description: 'Item#id'
                        description:
                          type: string
                        price:
                          type: number
                          format: integer
                        quantity:
                          type: number
                          default: 0.0
                          format: float
                        tax:
                          type: number
                          minimum: 0.0
                          maximum: 100
                        line_total:
                          type: number
                          format: integer
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    UpdateInvoice:
      description: Invoice Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              invoice:
                type: object
                required:
                  - company_id
                  - location_ids
                properties:
                  company_id:
                    type: integer
                  location_ids:
                    type: array
                    items:
                      type: integer
                  resource_type:
                    type: string
                    default: null
                    enum:
                      - WorkOrder
                  resource_id:
                    type: integer
                    default: null
                  status:
                    type: string
                    default: draft
                    enum:
                      - draft
                      - sent
                      - paid
                      - partially_paid
                  terms:
                    type: string
                    description: Sets the due date
                    enum:
                      - Due On Receipt
                      - Net 15
                      - Net 30
                      - Net 45
                  date_of_issue:
                    type: string
                    format: date-time
                  due_date:
                    type: string
                    format: date-time
                  discount:
                    type: number
                    format: float
                    description: In Dollars
                  billing_address:
                    type: string
                  invoice_message:
                    type: string
                  statement_memo:
                    type: string
                  custom_invoice_number:
                    type: string
                    description: Can update custom invoice number when the invoice in draft mode only
                  to_emails:
                    type: array
                    items:
                      type: string
                      format: email
                  invoice_items_attributes:
                    type: array
                    items:
                      type: object
                      required:
                        - item_name
                        - price
                        - quantity
                      properties:
                        id:
                          type: integer
                          description: required only when updating existing InvoiceItem else new InvoiceItem will get added.
                        item_id:
                          type: integer
                          description: 'Item#id'
                        _destory:
                          type: boolean
                          description: required to be true in combination of id attribute for removing existing InvoiceItem
                          default: false
                        description:
                          type: string
                        price:
                          type: number
                          format: integer
                        quantity:
                          type: number
                          default: 0.0
                          format: float
                        tax:
                          type: number
                          minimum: 0.0
                          maximum: 100
                        line_total:
                          type: number
                          format: integer
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    UpdateInboundInvoice:
      description: Update Inbound Invoice
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              invoice:
                type: object
                properties:
                  qbd_bill_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    CreatePurchaseOrder:
      description: Purchase Order Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              purchase_order:
                type: object
                required:
                  - vendor_id
                properties:
                  vendor_id:
                    type: integer
                  status:
                    type: integer
                    default: open
                    enum:
                      - open
                      - sent
                      - received
                      - closed
                  terms:
                    type: string
                    description: Sets the due date
                    enum:
                      - Due On Receipt
                      - Net 15
                      - Net 30
                      - Net 45
                  date_of_issue:
                    type: string
                    format: date-time
                  amount:
                    type: number
                    format: integer
                  tax_exempt:
                    type: boolean
                  billing_address:
                    type: string
                  shipping_address:
                    type: string
                  message:
                    type: string
                  statement_memo:
                    type: string
                  purchase_order_assignment_attributes:
                    type: object
                    properties:
                      work_order_id:
                        type: integer
                      trip_id:
                        type: integer
                  purchase_order_items_attributes:
                    type: array
                    items:
                      type: object
                      required:
                        - item_name
                        - price
                        - quantity
                      properties:
                        item_name:
                          type: string
                        description:
                          type: string
                        price:
                          type: number
                          format: integer
                        quantity:
                          type: number
                          default: 0.0
                          format: float
                        tax:
                          type: number
                          minimum: 0.0
                          maximum: 100
                        item_type:
                          type: string
                          description: Sets the Item Type
                          enum:
                            - material_code
                            - labor_rate
                            - material
                            - other
                        amount:
                          type: number
                          format: integer
                        unit_of_measure:
                          type: string
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    UpdatePurchaseOrder:
      description: PurchaseOrder Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              purchase_order:
                type: object
                required:
                  - vendor_id
                properties:
                  vendor_id:
                    type: integer
                  status:
                    type: integer
                    default: open
                    enum:
                      - open
                      - sent
                      - received
                      - closed
                  terms:
                    type: string
                    description: Sets the due date
                    enum:
                      - Due On Receipt
                      - Net 15
                      - Net 30
                      - Net 45
                  date_of_issue:
                    type: string
                    format: date-time
                  amount:
                    type: number
                    format: integer
                  tax_exempt:
                    type: boolean
                  billing_address:
                    type: string
                  shipping_address:
                    type: string
                  message:
                    type: string
                  statement_memo:
                    type: string
                  purchase_order_assignment_attributes:
                    type: object
                    properties:
                      id:
                        type: integer
                      work_order_id:
                        type: integer
                      trip_id:
                        type: integer
                  purchase_order_items_attributes:
                    type: array
                    items:
                      type: object
                      required:
                        - item_name
                        - price
                        - quantity
                      properties:
                        id:
                          type: integer
                          description: required only when updating existing PurchaseOrderItem else new PurchaseOrderItem will get added.
                        _destory:
                          type: boolean
                          description: required to be true in combination of id attribute for removing existing PurchaseOrderItem
                          default: false
                        item_name:
                          type: string
                        description:
                          type: string
                        price:
                          type: number
                          format: integer
                        quantity:
                          type: number
                          default: 0.0
                          format: float
                        tax:
                          type: number
                          minimum: 0.0
                          maximum: 100
                        item_type:
                          type: string
                          description: Sets the Item Type
                          enum:
                            - material_code
                            - labor_rate
                            - material
                            - other
                        amount:
                          type: number
                          format: integer
                        unit_of_measure:
                          type: string
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    CreatePayment:
      description: Payment Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              payment:
                type: object
                required:
                  - client_id
                  - reference_number
                properties:
                  client_id:
                    type: integer
                  payment_date:
                    type: string
                    format: date-time
                  payment_method:
                    type: integer
                    enum:
                      - credit_card
                      - debit_card
                      - cheque
                      - netbanking
                  reference_number:
                    type: string
                  amount:
                    type: number
                    format: integer
                  memo:
                    type: string
                  items:
                    type: array
                    items:
                      type: object
                      required:
                        - invoice_id
                      properties:
                        invoice_id:
                          type: integer
                        amount:
                          type: number
                          format: integer
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    UpdatePayment:
      description: Payment Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              payment:
                type: object
                required:
                  - client_id
                properties:
                  client_id:
                    type: integer
                  payment_date:
                    type: string
                    format: date-time
                  payment_method:
                    type: integer
                    enum:
                      - credit_card
                      - debit_card
                      - cheque
                      - netbanking
                  reference_number:
                    type: string
                  amount:
                    type: number
                    format: integer
                  memo:
                    type: string
                  items:
                    type: array
                    items:
                      type: object
                      required:
                        - invoice_id
                      properties:
                        invoice_id:
                          type: integer
                        amount:
                          type: number
                          format: integer
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    BillPayment:
      description: Bill Payment Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              bill_payment:
                type: object
                required:
                  - vendor_id
                  - ref_no
                  - ledger_account_id
                properties:
                  vendor_id:
                    type: integer
                  ledger_account_id:
                    type: integer
                  payment_date:
                    type: string
                    format: date-time
                  ref_no:
                    type: string
                  amount:
                    type: number
                    format: integer
                  memo:
                    type: string
                  items:
                    type: array
                    items:
                      type: object
                      required:
                        - invoice_id
                      properties:
                        invoice_id:
                          type: integer
                        amount:
                          type: number
                          format: integer
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    LedgerAccount:
      description: LedgerAccount Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              ledger_account:
                type: object
                required:
                  - name
                properties:
                  name:
                    type: string
                  account_type:
                    type: string
                  classification:
                    type: string
                  active:
                    type: boolean
                    default: true
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    ItemType:
      description: ItemType Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              item_type:
                type: object
                required:
                  - name
                  - type
                properties:
                  name:
                    type: string
                  type:
                    type: string
                    description: Sets the Type
                    enum:
                      - service
                      - product
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"

    UpdateItemType:
      description: ItemType Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              item_type:
                type: object
                required:
                  - name
                properties:
                  name:
                    type: string
                  qbd_connection_attributes:
                    $ref: "#/components/schemas/QbdConnection"


    Item:
      description: Item Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              item:
                type: object
                required:
                  - item_type_id
                  - name
                  - type
                  - income_account_id
                  - expense_account_id
                  - asset_account_id
                properties:
                  item_type_id:
                    type: integer
                  department_id:
                    type: integer
                  name:
                    type: string
                  type:
                    type: string
                    description: |
                      service when item_type#type is service
                      inventory/non_inventory when item_type#type is product
                    enum:
                      - service
                      - inventory
                      - non_inventory
                  is_sales_type:
                    type: boolean
                    default: false
                    description: must be true if type is inventory or is_purchase_type is false
                  is_purchase_type:
                    type: boolean
                    default: false
                    description: must be true if type is inventory or is_sales_type is false
                  income_account_id:
                    type: integer
                    description: required when is_sales_type is true
                  expense_account_id:
                    type: integer
                    description: required when is_purchase_type is true
                  asset_account_id:
                    type: integer
                    description: required when type is inventory
                  initial_quantity:
                    type: number
                    format: float
                    description: required when type is inventory
                  reorder_point:
                    type: number
                    format: float
                    description: optional, applicable for inventory type
                  inventory_start_date:
                    type: string
                    format: date-time
                    description: required when type is inventory
                  unit_price:
                    type: integer
                  purchase_cost:
                    type: integer
                  sales_description:
                    type: string
                    format: text
                  purchase_description:
                    type: string
                    format: text

    UpdateItem:
      description: Item Object
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              item:
                type: object
                required:
                  - item_type_id
                  - name
                  - type
                  - income_account_id
                  - expense_account_id
                  - asset_account_id
                properties:
                  name:
                    type: string
                  type:
                    type: string
                    description: |
                      service when item_type#type is service
                      inventory/non_inventory when item_type#type is product
                    enum:
                      - service
                      - inventory
                      - non_inventory
                  is_sales_type:
                    type: boolean
                    default: false
                    description: must be true if type is inventory or is_purchase_type is false
                  is_purchase_type:
                    type: boolean
                    default: false
                    description: must be true if type is inventory or is_sales_type is false
                  income_account_id:
                    type: integer
                    description: required when is_sales_type is true
                  expense_account_id:
                    type: integer
                    description: required when is_purchase_type is true
                  asset_account_id:
                    type: integer
                    description: required when type is inventory
                  reorder_point:
                    type: number
                    format: float
                    description: optional, applicable for inventory type
                  unit_price:
                    type: integer
                  purchase_cost:
                    type: integer
                  sales_description:
                    type: string
                    format: text
                  purchase_description:
                    type: string
                    format: text

  ############################ RequestBodies End ###################
  schemas:
    TripPriority:
      type: object
      properties:
        label:
          type: string
        minutes:
          type: integer
        description:
          type: string

    ExternalConnection:
      type: object
      required:
        - provider
        - external_id
      properties:
        provider:
          type: string
        external_id:
          type: string
        additional_info:
          type: object
          additionalProperties: {}

    QbdConnection:
      type: object
      required:
        - external_id
      properties:
        external_id:
          type: string
        additional_info:
          type: object
          additionalProperties: {}

    Trade:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
        sic_code:
          type: string
        authorization_number:
          type: string
        licenses:
          type: boolean
        state:
          type: string
        no_equipment:
          type: boolean
          default: false
        parent_id:
          type: integer

    WorkOrder:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        work_order_type:
          type: string
        location_ids:
          type: array
          items:
            type: integer
        service_system:
          type: string
        no_dispatch_reason:
          type: string
        extended_status:
          type: string
        extended_status_text:
          type: string
        instructions:
          type: string
        work_order_name:
          type: string
        problem_type:
          type: string
        priority:
          type: string
        contract_id:
          type: integer
          description: 'Only for scheduled WorkOrder'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        trips:
          type: array
          items:
            $ref: '#/components/schemas/Trip'
    Ivr:
      type: object
      properties:
        phone_type:
          type: string
        phone_no:
          type: string
        pin:
          type: string
        instructions:
          type: string
    WorkOrderNote:
      type: object
      properties:
        notes:
          type: string
    TradesmanTrip:
      type: object
      properties:
        id:
          type: integer
        tradesman_id:
          type: integer
        start_date:
          type: string
          format: date-time
        end_date:
          type: string
          format: date-time
    VendorTrip:
      type: object
      properties:
        id:
          type: integer
        vendor_id:
          type: integer
        start_date:
          type: string
          format: date-time
        end_date:
          type: string
          format: date-time
    Trip:
      type: object
      properties:
        id:
          type: integer
        position:
          type: integer
        start_date:
          type: string
          format: date-time
        end_date:
          type: string
          format: date-time
        nte:
          type: number
          format: currency
        equipments:
          type: array
          items:
            type: string
        description:
          type: string
          format: text
        external_status:
          type: string
        contractor_id:
          type: integer
          description: 'When Trip is assigned to a Vendor'
        trade_id:
          type: integer
        priority:
          $ref: '#/components/schemas/TripPriority'
        ivr:
          $ref: '#/components/schemas/Ivr'
        ftc_work_order_id:
          type: string
        extended_status:
          type: string
        extended_status_text:
          type: string
        tradesmen_trips:
          type: array
          items:
            $ref: '#/components/schemas/TradesmanTrip'
        external_connections:
          type: array
          items:
            $ref: '#/components/schemas/ExternalConnection'

    Company:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
        email:
          type: string
        phone:
          type: string
        fax:
          type: string
        subdomain:
          type: string
        contacts:
          type: array
          items:
            $ref: "#/components/schemas/Contact"
        logo:
          $ref: "#/components/schemas/CompanyLogo"
        qbd_customer_connection:
          $ref: "#/components/schemas/QbdConnection"
        qbd_vendor_connection:
          $ref: "#/components/schemas/QbdConnection"
    Contact:
      type: object
      properties:
        id:
          type: integer
        first_name:
          type: string
        last_name:
          type: string
        title:
          type: string
        email:
          type: string
          format: email
        phone:
          type: string
        extension:
          type: string
        mobile:
          type: string
        is_billing_person:
          type: boolean
    CompanyLogo:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        versions:
          type: object
          properties:
            icon:
              type: string
              description: "64x64"
            thumb:
              type: string
              description: "128x128"
            small:
              type: string
              description: "300x300"
            medium:
              type: string
              description: "450x450"
            big:
              type: string
              description: "600x600"
    LocationImage:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        versions:
          type: object
          properties:
            thumb:
              type: string
              description: "128x128"
            small:
              type: string
              description: "300x300"
            medium:
              type: string
              description: "450x450"
    Invoice:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        company_id:
          type: integer
        location_ids:
          type: array
          items:
            type: integer
        resource_type:
          type: string
        resource_id:
          type: integer
        status:
          type: string
        terms:
          type: string
        date_of_issue:
          type: string
          format: date-time
        due_date:
          type: string
          format: date-time
        discount:
          type: number
          format: float
        total:
          type: number
          format: integer
        billing_address:
          type: string
        invoice_message:
          type: string
        statement_memo:
          type: string
        invoice_number:
          type: string
        custom_invoice_number:
          type: string
        invoice_items:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
              description:
                type: string
              price:
                type: number
                format: integer
              quantity:
                type: number
                format: float
              tax:
                type: number
                format: float
              line_total:
                type: number
                format: float
              item:
                $ref: '#/components/schemas/Item'
        qbd_connection:
          $ref: '#/components/schemas/QbdConnection'
        company:
          $ref: '#/components/schemas/Customer'

    PurchaseOrder:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        vendor_id:
          type: integer
        terms:
          type: string
          description: Sets the due date
          enum:
            - Due On Receipt
            - Net 15
            - Net 30
            - Net 45
        date_of_issue:
          type: string
          format: date-time
        billing_address:
          $ref: '#/components/schemas/Address'
        shipping_address:
          $ref: '#/components/schemas/Address'
        amount:
          type: number
          format: integer
        tax_exempt:
          type: boolean
        message:
          type: string
        statement_memo:
          type: string
        status:
          type: integer
          default: draft
          enum:
            - open
            - sent
            - received
            - closed
        purchase_order_assignment:
          type: object
          properties:
            id:
              type: integer
            work_order_id:
              type: integer
            trip_id:
              type: integer
        purchase_order_items:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
              item_name:
                type: string
              item_type:
                type: string
                enum:
                  - material_code
                  - labor_rate
                  - material
                  - other
              description:
                type: string
              quantity:
                type: number
                default: 0.0
                format: float
              price:
                type: number
                format: integer
              tax:
                type: number
                format: float
              amount:
                type: number
                format: integer
              unit_of_measure:
                type: string
        qbd_connection:
          $ref: '#/components/schemas/QbdConnection'
        qbd_vendor_connection:
          $ref: "#/components/schemas/QbdConnection"

    Payment:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        client_id:
          type: integer
        payment_date:
          type: string
          format: date-time
        payment_method:
          type: integer
          enum:
            - credit_card
            - debit_card
            - cheque
            - netbanking
        reference_number:
          type: string
        price:
          type: number
          format: integer
        available_balance:
          type: number
          format: integer
        memo:
          type: string
        status:
          type: integer
          default: nil
          enum:
            - unapplied
            - partialy_unapplied
            - closed
        invoice_payments:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
              invoice_id:
                type: integer
              payment_id:
                type: integer
              amount:
                type: number
                format: integer
        qbd_connection:
          $ref: '#/components/schemas/QbdConnection'
        invoice:
          $ref: '#/components/schemas/Invoice'
        qbd_customer_connection:
          $ref: '#/components/schemas/QbdConnection'

    BillPayment:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        vendor_id:
          type: integer
        payment_date:
          type: string
          format: date-time
        ref_no:
          type: string
        price:
          type: number
          format: integer
        balance:
          type: number
          format: integer
        memo:
          type: string
        bill_payment_items:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
              invoice_id:
                type: integer
              payment_id:
                type: integer
              amount:
                type: number
                format: integer
        qbd_connection:
          $ref: '#/components/schemas/QbdConnection'
        ledger_account:
          $ref: '#/components/schemas/LedgerAccount'
        invoice:
          $ref: '#/components/schemas/Invoice'
        qbd_vendor_connection:
          $ref: '#/components/schemas/QbdConnection'

    LedgerAccount:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        company_id:
          type: integer
        name:
          type: string
        account_type:
          type: string
        active:
          type: boolean
        classification:
          type: string
        qbd_connection:
          $ref: '#/components/schemas/QbdConnection'

    ItemType:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        company_id:
          type: integer
        name:
          type: string
        type:
          type: integer
          description: Sets the Type
          enum:
            - service
            - product
        qbd_connection:
          $ref: '#/components/schemas/QbdConnection'

    UpdateItemType:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        company_id:
          type: integer
        name:
          type: string
        qbd_connection:
          $ref: '#/components/schemas/QbdConnection'

    Item:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        item_type_id:
          type: integer
        department_id:
          type: integer
        name:
          type: string
        type:
          type: integer
          description: Sets the Type
          enum:
            - service
            - inventory
            - non_inventory
        is_sales_type:
          type: boolean
          default: false
          description: must be true if type is inventory or is_purchase_type is false
        is_purchase_type:
          type: boolean
          default: false
          description: must be true if type is inventory or is_sales_type is false
        income_account_id:
          type: integer
          description: required when is_sales_type is true
        expense_account_id:
          type: integer
          description: required when is_purchase_type is true
        asset_account_id:
          type: integer
          description: required when type is inventory
        initial_quantity:
          type: number
          format: float
          description: required when type is inventory
        reorder_point:
          type: number
          format: float
          description: optional, applicable for inventory type
        inventory_start_date:
          type: string
          format: date-time
          description: required when type is inventory
        unit_price:
          type: integer
        purchase_cost:
          type: integer
        sales_description:
          type: string
          format: text
        purchase_description:
          type: string
          format: text

    UpdateItem:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        item_type_id:
          type: integer
        department_id:
          type: integer
        name:
          type: string
        type:
          type: integer
          description: Sets the Type
          enum:
            - service
            - inventory
            - non_inventory
        is_sales_type:
          type: boolean
          default: false
          description: must be true if type is inventory or is_purchase_type is false
        is_purchase_type:
          type: boolean
          default: false
          description: must be true if type is inventory or is_sales_type is false
        income_account_id:
          type: integer
          description: required when is_sales_type is true
        expense_account_id:
          type: integer
          description: required when is_purchase_type is true
        asset_account_id:
          type: integer
          description: required when type is inventory
        reorder_point:
          type: number
          format: float
          description: optional, applicable for inventory type
        unit_price:
          type: integer
        purchase_cost:
          type: integer
        sales_description:
          type: string
          format: text
        purchase_description:
          type: string
          format: text

    Client:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
        email:
          type: string
        phone:
          type: string
        fax:
          type: string
        subdomain:
          type: string
        contacts:
          type: array
          items:
            $ref: "#/components/schemas/Contact"
        logo:
          $ref: "#/components/schemas/CompanyLogo"
        qbd_customer_connection:
          $ref: "#/components/schemas/QbdConnection"

    Customer:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
        email:
          type: string
        phone:
          type: string
        fax:
          type: string
        subdomain:
          type: string
        description:
          type: string
        qbd_customer_connection:
          $ref: "#/components/schemas/QbdConnection"

    Vendor:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
        email:
          type: string
        phone:
          type: string
        fax:
          type: string
        subdomain:
          type: string
        contacts:
          type: array
          items:
            $ref: "#/components/schemas/Contact"
        logo:
          $ref: "#/components/schemas/CompanyLogo"
        qbd_vendor_connection:
          $ref: "#/components/schemas/QbdConnection"

    Tradesman:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        email:
          type: string
          format: email
        first_name:
          type: string
        last_name:
          type: string
        ftc_user_name:
          type: string
        phone:
          type: string
        ftc_id:
          type: string
        picture_url:
          type: string
          format: url

    Location:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        company_id:
          type: integer
        name:
          type: string
        tax_exempt:
          type: boolean
        address:
          $ref: '#/components/schemas/Address'
        billing_address:
          $ref: '#/components/schemas/Address'
        contacts:
          $ref: "#/components/schemas/Contact"
        image:
          $ref: "#/components/schemas/LocationImage"
        qbd_connection:
          $ref: '#/components/schemas/QbdConnection'
        company:
          $ref: '#/components/schemas/Customer'

    Address:
      type: object
      required:
        - address1
        - city
        - state
        - country
        - lat
        - lng
      properties:
        apt_or_suite:
          type: string
        address1:
          type: string
        city:
          type: string
        district:
          type: string
        state:
          type: string
        zip_code:
          type: string
        country:
          type: string
          description: 'ISO 3166-1 alpha-2'
          example: 'US'
        lat:
          type: number
        lng:
          type: number
        place_id:
          type: string
    User:
      type: object
      properties:
        id:
          type: integer
        first_name:
          type: string
        last_name:
          type: string
        email:
          type: string
        last_sign_in_company_id:
          type: string

    PaginationInfo:
      type: object
      properties:
        current_page:
          type: integer
          description: Current page number
        next_page:
          type: integer
          description: Next page number
        prev_page:
          type: integer
          description: Previous page number
        total_pages:
          type: integer
          description: Total Number of pages
        total_count:
          type: integer
          description: Total number of records
