openapi: 3.0.0
info:
  title: Assignments
  description: This document lists Autopass parts technical information and assignments endpoints.
  version: 1.0.0
servers:
  - url: https://api.autopass.pro
    description: Live server
    x-environment: live
  - url: https://api-prelive.autopass.pro
    description: Prelive server
    x-environment: prelive
paths:
  /assignments:
    get:
      description: List parts AM assigned to a KType and an application.
      summary: List assignments
      operationId: list-assignments
      parameters:
        - in: query
          name: ktypnr
          required: true
          schema:
            type: integer
            example: 470
        - in: query
          name: application_id
          schema:
            type: integer
            example: 2
        - in: query
          name: filters
          schema:
            type: string
            example: '{10:["100"],520:["true"],150:["turbo"]}'
      responses:
        200:
          description: OK.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/KtypnrRefeqAssignments"
    post:
      description: Assign a part AM to a KType and an application.
      summary: Create an assignment
      operationId: create-assignment
      parameters:
        - in: query
          name: ktypnr
          required: true
          schema:
            type: integer
            example: 470
        - in: query
          name: application_id
          required: true
          schema:
            type: integer
            example: 2
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/KtypnrRefeqAssignmentPost"
        required: true
      responses:
        200:
          description: OK.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/KtypnrRefeqAssignment"
  /assignment/{assignment_id}:
    patch:
      description: Patch an assignment.
      summary: Patch an assignment
      operationId: patch-assignment
      parameters:
        - in: path
          name: assignment_id
          required: true
          schema:
            type: integer
            example: 100
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AssignmentPost"
        required: true
      responses:
        200:
          description: OK.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/KtypnrRefeqAssignment"
    delete:
      description: Delete an assignment.
      summary: Delete an assignment
      operationId: delete-assignment
      parameters:
        - in: path
          name: assignment_id
          required: true
          schema:
            type: integer
            example: 1
      responses:
        200:
          description: OK.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/KtypnrRefeqAssignment"
  /assignment-criteria:
    get:
      description: List criteria for a specific assignment identified by its KType, application and part AM.
      summary: List assignment criteria
      operationId: list-assignment-criteria
      parameters:
        - in: query
          name: ktypnr
          required: true
          schema:
            type: integer
            example: 150
        - in: query
          name: application_id
          required: true
          schema:
            type: integer
            example: 2
        - in: query
          name: part_am_id
          required: true
          schema:
            type: integer
            example: 437
      responses:
        200:
          description: OK.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AssignmentCriteria"
    post:
      description: Create an assignment criteria.
      summary: Create an assignment criteria
      operationId: create-assignment-criteria
      parameters:
        - in: query
          name: ktypnr
          required: true
          schema:
            type: integer
            example: 470
        - in: query
          name: application_id
          required: true
          schema:
            type: integer
            example: 2
      requestBody:
        content:
          application/json:
            schema:
              items:
                $ref: "#/components/schemas/RefeqAssignmentCriteriaPost"
                type: array
        required: true
      responses:
        200:
          description: OK.
    delete:
      description: Delete an assignment criteria.
      summary: Delete an assignment criteria
      operationId: delete-assignment-criteria
      parameters:
        - in: query
          name: ktypnr
          required: true
          schema:
            type: integer
            example: 470
        - in: query
          name: application_id
          required: true
          schema:
            type: integer
            example: 2
        - in: query
          name: part_am_id
          required: true
          schema:
            type: integer
            example: 2
        - in: query
          name: group
          required: true
          schema:
            type: integer
            example: 1
        - in: query
          name: display_order
          required: true
          schema:
            type: integer
            example: 1
        - in: query
          name: label_id
          required: true
          schema:
            type: integer
            example: 1
      responses:
        200:
          description: OK.
    patch:
      description: Patch an assignment criteria.
      summary: Patch an assignment criteria
      operationId: patch-assignment-criteria
      parameters:
        - in: query
          name: ktypnr
          required: true
          schema:
            type: integer
            example: 470
        - in: query
          name: application_id
          required: true
          schema:
            type: integer
            example: 2
        - in: query
          name: part_am_id
          required: true
          schema:
            type: integer
            example: 2
        - in: query
          name: group
          required: true
          schema:
            type: integer
            example: 1
        - in: query
          name: display_order
          required: true
          schema:
            type: integer
            example: 1
        - in: query
          name: label_id
          required: true
          schema:
            type: integer
            example: 1
      requestBody:
        content:
          application/json:
            schema:
              items:
                $ref: "#/components/schemas/RefeqAssignmentCriteriaPost"
                type: array
        required: true
      responses:
        200:
          description: OK.

  /technical-properties:
    get:
      description: List technical properties.
      summary: List technical properties
      operationId: list-technical-properties
      parameters:
        - in: query
          name: ktypnr
          schema:
            type: integer
            example: 150
        - in: query
          name: application_id
          schema:
            type: integer
            example: 437
      responses:
        200:
          description: OK.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TechInformationLabels"
  /parts-am/{part_am_id}/ktypnrs:
    get:
      description: List KTypnrs to which the part AM is assigned.
      summary: List part AM's KTypnrs
      operationId: list-part-ktypnrs
      parameters:
        - in: path
          required: true
          name: part_am_id
          schema:
            type: integer
            example: 100
      responses:
        200:
          description: OK.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Ktypnrs"
security:
  - ApiKeyAuth: []
  - ApiKeyHeader: []
  - ApiKeyQuery: []
  - BearerAuth: []
components:
  securitySchemes:
    ApiKeyQuery:
      type: apiKey
      in: query
      name: access_token
    ApiKeyHeader:
      type: apiKey
      in: header
      name: X-Access-Token
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  parameters:
    PaginationLimit:
      in: query
      name: limit
      example: 20
      schema:
        type: integer
      description: Limits results to given limit.
    PaginationOffset:
      in: query
      name: offset
      example: 10
      schema:
        type: integer
      description: List results starting to given offset.
  schemas:
    Meta:
      type: object
      properties:
        limit:
          type: integer
          example: 100
        offset:
          type: integer
          example: 20
        total:
          type: integer
          example: 200

    Application:
      properties:
        application_id:
          type: number
          example: 1
        family:
          type: object
          properties:
            family_id:
              type: number
              example: 1
            label:
              type: string
              example: "Frein"
        position:
          type: object
          properties:
            position_id:
              type: number
              example: 1
            label:
              type: string
              example: "AV D/G"
    Applications:
      type: array
      items:
        $ref: "#/components/schemas/Application"
    ApplicationCollection:
      type: object
      properties:
        meta:
          $ref: "#/components/schemas/Meta"
        applications:
          $ref: "#/components/schemas/Applications"
    Ktypnrs:
      type: object
      properties:
        meta:
          $ref: "#/components/schemas/Meta"
        ktypnrs:
          type: array
          items:
            type: integer
    AssignmentPost:
      type: object
      properties:
        status:
          type: string
          enum: ["A", "U", "S"]
          default: A
          example: A
        pairing_group:
          type: integer
          example: 3
    KtypnrRefeqAssignmentPost:
      type: object
      properties:
        part_am_id:
          type: integer
          example: 2
        equip_id:
          type: integer
          example: 4
        status:
          type: string
          enum: ["A", "U", "S"]
          default: A
          example: A
        pairing_group:
          type: integer
          example: 3
    KtypnrRefeqAssignment:
      type: object
      properties:
        assignment_id:
          type: integer
          example: 1
        ktypnr:
          type: integer
          example: 750
        application_id:
          type: integer
          example: 2
        part_am_id:
          type: integer
          example: 2
        part_am_code:
          type: string
          example: DDF1225
        equip_id:
          type: integer
          example: 4
        equip_name:
          type: string
          example: FERODO
        status:
          type: string
          enum: ["A", "U", "S"]
          default: A
          example: A
        pairing_group:
          type: integer
          example: 3
        technical_information:
          type: array
          items:
            $ref: "#/components/schemas/RefeqTechInformation"
        assignment_criteria:
          type: array
          items:
            $ref: "#/components/schemas/RefeqAssignmentCriteria"
        links:
          $ref: "#/components/schemas/KtypnrRefeqAssignmentLinks"
    KtypnrRefeqAssignmentLinks:
      type: object
      properties:
        part_am:
          type: string
          example: https://api.autopass.pro/parts-am/123
    KtypnrRefeqAssignments:
      type: object
      properties:
        meta:
          $ref: "#/components/schemas/Meta"
        assigments:
          type: array
          items:
            $ref: "#/components/schemas/KtypnrRefeqAssignment"
    TechInformationLabels:
      type: object
      properties:
        meta:
          $ref: "#/components/schemas/Meta"
        labels:
          type: array
          items:
            $ref: "#/components/schemas/TechInformationLabel"
    AssignmentCriteria:
      type: object
      properties:
        meta:
          $ref: "#/components/schemas/Meta"
        assignment_criteria:
          type: array
          items:
            $ref: "#/components/schemas/AssignmentCriteriaObject"
    AssignmentCriteriaObject:
      type: object
      properties:
        label:
          type: string
          example: "Hauteur [mm]"
        value:
          type: string
          example: "string"
    TechInformationLabel:
      type: object
      properties:
        tech_information_id:
          type: integer
          example: 5
        label:
          type: string
          example: Hauteur [mm]
        values:
          type: array
          items:
            type: string
    TechInformationValues:
      type: object
      properties:
        meta:
          $ref: "#/components/schemas/Meta"
        values:
          $ref: "#/components/schemas/TechInformationValueObjects"
    TechInformationValueObjects:
      type: array
      items:
        $ref: "#/components/schemas/TechInformationValue"
    TechInformationValue:
      type: object
      properties:
        label_id:
          type: integer
          example: 5
        label_name:
          type: string
          example: Hauteur [mm]
        value:
          type: string
    RefeqTechInformation:
      type: object
      properties:
        label_id:
          type: integer
          example: 5
        label_name:
          type: string
          example: Hauteur [mm]
        info_name:
          type: string
          example: 48.5
    RefeqAssignmentCriteria:
      type: object
      properties:
        label_id:
          type: integer
          example: 5
        label_name:
          type: string
          example: Code moteur
        group:
          type: integer
          example: 2
        info_name:
          type: string
          example: HNY
    RefeqAssignmentCriteriaPost:
      type: object
      properties:
        part_am_id:
          type: integer
          example: 5
        group:
          type: integer
          example: 2
        display_order:
          type: integer
          example: 3
        label_id:
          type: integer
          example: 5
        value:
          type: string
          example: HNY
        status:
          type: string
          example: A
