---
/erm/agreements:
  get:
    x-mojo-to: ERM::Agreements#list
    operationId: listErmAgreements
    tags:
      - agreement
    summary: List agreements
    produces:
      - application/json
    parameters:
      - description: Case insensitive search on agreement agreement_id
        in: query
        name: agreement_id
        required: false
        type: integer
      - description: Case insensitive search on agreement vendor_id
        in: query
        name: vendor_id
        required: false
        type: integer
      - description: Case insensitive search on agreement name
        in: query
        name: name
        required: false
        type: string
      - description: Case insensitive search on agreement description
        in: query
        name: description
        required: false
        type: string
      - description: Case insensitive search on agreement status
        in: query
        name: status
        required: false
        type: string
      - description: Case insensitive search on agreement closure_reason
        in: query
        name: closure_reason
        required: false
        type: string
      - description: Case insensitive search on agreement is_perpetual
        in: query
        name: is_perpetual
        required: false
        type: boolean
      - description: Case insensitive search on agreement renewal_priority
        in: query
        name: renewal_priority
        required: false
        type: string
      - description: Case insensitive search on agreement license_info
        in: query
        name: license_info
        required: false
        type: string
      - description: filter by expired agreements
        in: query
        name: max_expiration_date
        type: string
        format: date
      - $ref: "../swagger.yaml#/parameters/match"
      - $ref: "../swagger.yaml#/parameters/order_by"
      - $ref: "../swagger.yaml#/parameters/page"
      - $ref: "../swagger.yaml#/parameters/per_page"
      - $ref: "../swagger.yaml#/parameters/q_param"
      - $ref: "../swagger.yaml#/parameters/q_body"
      - $ref: "../swagger.yaml#/parameters/q_header"
    responses:
      200:
        description: A list of agreement
        schema:
          items:
            $ref: "../swagger.yaml#/definitions/erm_agreement"
          type: array
      400:
        description: Bad request
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      403:
        description: Access forbidden
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      500:
        description: |-
          Internal server error. Possible `error_code` attribute values:
          * `internal_server_error`
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      503:
        description: Under maintenance
        schema:
          $ref: "../swagger.yaml#/definitions/error"
    x-koha-authorization:
      permissions:
        erm: 1
  post:
    x-mojo-to: ERM::Agreements#add
    operationId: addErmAgreements
    tags:
      - agreement
    summary: Add agreement
    consumes:
      - application/json
    produces:
      - application/json
    parameters:
      - description: A JSON object containing information about the new agreement
        in: body
        name: body
        required: true
        schema:
            $ref: "../swagger.yaml#/definitions/erm_agreement"
    responses:
      201:
        description: A successfully created agreement
        schema:
          items:
            $ref: "../swagger.yaml#/definitions/erm_agreement"
      400:
        description: Bad parameter
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      401:
        description: Authentication required
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      403:
        description: Access forbidden
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      404:
        description: Ressource not found
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      409:
        description: Conflict in creating resource
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      413:
        description: Payload too large
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      500:
        description: |-
          Internal server error. Possible `error_code` attribute values:
          * `internal_server_error`
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      503:
        description: Under maintenance
        schema:
          $ref: "../swagger.yaml#/definitions/error"
    x-koha-authorization:
      permissions:
        erm: 1
"/erm/agreements/{agreement_id}":
  get:
    x-mojo-to: ERM::Agreements#get
    operationId: getErmAgreements
    tags:
      - agreement
    summary: Get agreement
    produces:
      - application/json
    parameters:
      - $ref: "../swagger.yaml#/parameters/agreement_id_pp"
    responses:
      200:
        description: An agreement
        schema:
          items:
            $ref: "../swagger.yaml#/definitions/erm_agreement"
      401:
        description: Authentication required
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      403:
        description: Access forbidden
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      404:
        description: Ressource not found
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      500:
        description: |-
          Internal server error. Possible `error_code` attribute values:
          * `internal_server_error`
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      503:
        description: Under maintenance
        schema:
          $ref: "../swagger.yaml#/definitions/error"
    x-koha-authorization:
      permissions:
        erm: 1
    x-koha-embed:
      - periods
      - user_roles
      - user_roles.patron
      - agreement_licenses
      - agreement_licenses.license
      - agreement_relationships
      - agreement_relationships.agreement
      - agreement_relationships.related_agreement
      - documents
      - packages
  put:
    x-mojo-to: ERM::Agreements#update
    operationId: updateErmAgreements
    tags:
      - agreement
    summary: Update agreement
    consumes:
      - application/json
    produces:
      - application/json
    parameters:
      - $ref: "../swagger.yaml#/parameters/agreement_id_pp"
      - name: body
        in: body
        description: A JSON object containing new information about existing agreement
        required: true
        schema:
          $ref: "../swagger.yaml#/definitions/erm_agreement"

    responses:
      200:
        description: A successfully updated agreement
        schema:
          items:
            $ref: "../swagger.yaml#/definitions/erm_agreement"
      400:
        description: Bad parameter
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      403:
        description: Access forbidden
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      404:
        description: Ressource not found
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      409:
        description: Conflict in updating resource
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      413:
        description: Payload too large
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      500:
        description: |-
          Internal server error. Possible `error_code` attribute values:
          * `internal_server_error`
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      503:
        description: Under maintenance
        schema:
          $ref: "../swagger.yaml#/definitions/error"
    x-koha-authorization:
      permissions:
        erm: 1
    x-koha-embed:
      - periods
      - user_roles
      - agreement_licenses
      - agreement_relationships
      - documents
  delete:
    x-mojo-to: ERM::Agreements#delete
    operationId: deleteErmAgreements
    tags:
      - agreement
    summary: Delete agreement
    produces:
      - application/json
    parameters:
      - $ref: "../swagger.yaml#/parameters/agreement_id_pp"
    responses:
      204:
        description: Agreement deleted
      400:
        description: Agreement deletion failed
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      401:
        description: Authentication required
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      403:
        description: Access forbidden
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      404:
        description: Ressource not found
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      409:
        description: Conflict in deleting resource
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      500:
        description: |-
          Internal server error. Possible `error_code` attribute values:
          * `internal_server_error`
        schema:
          $ref: "../swagger.yaml#/definitions/error"
      503:
        description: Under maintenance
        schema:
          $ref: "../swagger.yaml#/definitions/error"
    x-koha-authorization:
      permissions:
        erm: 1
