openapi: 3.0.0
info:
  title: Asset Part API
  description: API for managing asset parts
  version: 1.0.0
  contact:
    name: Repzo
    url: https://repzo.com

servers:
  - url: https://sv.api.repzo.me
    description: Production server
  - url: https://staging.sv.api.repzo.me
    description: Staging server

tags:
  - name: Asset Part
    description: Operations related to asset part management

paths:
  /asset-part:
    get:
      tags:
        - Asset Part
      summary: Get all asset parts
      description: Retrieve a list of all asset parts with optional filtering and pagination
      parameters:
        - name: limit
          in: query
          description: Maximum number of records to return
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 50
        - name: offset
          in: query
          description: Number of records to skip for pagination
          required: false
          schema:
            type: integer
            minimum: 0
            default: 0
        - name: sort
          in: query
          description: Field to sort by
          required: false
          schema:
            type: string
        - name: order
          in: query
          description: Sort order (asc or desc)
          required: false
          schema:
            type: string
            enum: [asc, desc]
            default: desc
        - name: filter
          in: query
          description: Filter conditions in JSON format
          required: false
          schema:
            type: string
        - name: search
          in: query
          description: Search term for text fields
          required: false
          schema:
            type: string
      responses:
        "200":
          description: List of asset parts retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/AssetPart"
                  total:
                    type: integer
                    description: Total number of records
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    post:
      tags:
        - Asset Part
      summary: Create a new asset part
      description: Create a new asset part with the provided data
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AssetPartInput"
      responses:
        "201":
          description: Asset part created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/AssetPart"
        "400":
          description: Bad request
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

  /asset-part/{id}:
    get:
      tags:
        - Asset Part
      summary: Get asset part by ID
      description: Retrieve a specific asset part by its ID
      parameters:
        - name: id
          in: path
          required: true
          description: Asset part ID
          schema:
            type: string
      responses:
        "200":
          description: Asset part retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/AssetPart"
        "404":
          description: Asset part not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    put:
      tags:
        - Asset Part
      summary: Update asset part
      description: Update an existing asset part with new data
      parameters:
        - name: id
          in: path
          required: true
          description: Asset part ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AssetPartInput"
      responses:
        "200":
          description: Asset part updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/AssetPart"
        "400":
          description: Bad request
        "404":
          description: Asset part not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error
    delete:
      tags:
        - Asset Part
      summary: Delete asset part
      description: Delete an existing asset part
      parameters:
        - name: id
          in: path
          required: true
          description: Asset part ID
          schema:
            type: string
      responses:
        "200":
          description: Asset part deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Asset part deleted successfully
        "404":
          description: Asset part not found
        "401":
          description: Unauthorized
        "500":
          description: Internal server error

components:
  schemas:
    AssetPart:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier for the asset part
          example: "60f7b1b3e4b0e8b3f8b3f8b3"
        partNumber:
          type: string
          description: Unique part number
          example: "EP-001-2023"
        name:
          type: string
          description: Name of the asset part
          example: "Engine Valve"
        description:
          type: string
          description: Description of the asset part
        partType:
          type: string
          description: Asset part type ID
          example: "60f7b1b3e4b0e8b3f8b3f8b4"
        manufacturer:
          type: string
          description: Manufacturer name
          example: "ABC Manufacturing"
        model:
          type: string
          description: Part model number
        specifications:
          type: object
          additionalProperties: true
          description: Technical specifications
          example:
            material: "Stainless Steel"
            diameter: "25mm"
            length: "50mm"
        compatibleAssets:
          type: array
          items:
            type: string
          description: List of compatible asset IDs
        supplier:
          type: string
          description: Primary supplier ID
        cost:
          type: number
          format: double
          minimum: 0
          description: Current cost of the part
        currency:
          type: string
          description: Currency code
          example: "USD"
        minStockLevel:
          type: integer
          minimum: 0
          description: Minimum stock level
        maxStockLevel:
          type: integer
          minimum: 0
          description: Maximum stock level
        reorderPoint:
          type: integer
          minimum: 0
          description: Reorder point threshold
        leadTime:
          type: integer
          description: Lead time in days
          example: 7
        warrantyPeriod:
          type: integer
          description: Warranty period in days
          example: 365
        category:
          type: string
          description: Part category
          example: "Engine"
        subcategory:
          type: string
          description: Part subcategory
          example: "Valves"
        isActive:
          type: boolean
          default: true
          description: Whether the part is active
        barcode:
          type: string
          description: Barcode for the part
        qrCode:
          type: string
          description: QR code for the part
        images:
          type: array
          items:
            type: string
            format: uri
          description: Part images URLs
        documents:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              url:
                type: string
                format: uri
              type:
                type: string
                enum: [manual, specification, certificate, warranty]
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
        createdAt:
          type: string
          format: date-time
          description: Record creation timestamp
          example: "2023-01-15T08:00:00Z"
        updatedAt:
          type: string
          format: date-time
          description: Record last update timestamp
          example: "2023-01-15T10:30:00Z"
      required:
        - partNumber
        - name
        - partType

    AssetPartInput:
      type: object
      properties:
        partNumber:
          type: string
          description: Unique part number
          example: "EP-001-2023"
        name:
          type: string
          description: Name of the asset part
          example: "Engine Valve"
        description:
          type: string
          description: Description of the asset part
        partType:
          type: string
          description: Asset part type ID
          example: "60f7b1b3e4b0e8b3f8b3f8b4"
        manufacturer:
          type: string
          description: Manufacturer name
          example: "ABC Manufacturing"
        model:
          type: string
          description: Part model number
        specifications:
          type: object
          additionalProperties: true
          description: Technical specifications
          example:
            material: "Stainless Steel"
            diameter: "25mm"
            length: "50mm"
        compatibleAssets:
          type: array
          items:
            type: string
          description: List of compatible asset IDs
        supplier:
          type: string
          description: Primary supplier ID
        cost:
          type: number
          format: double
          minimum: 0
          description: Current cost of the part
        currency:
          type: string
          description: Currency code
          example: "USD"
        minStockLevel:
          type: integer
          minimum: 0
          description: Minimum stock level
        maxStockLevel:
          type: integer
          minimum: 0
          description: Maximum stock level
        reorderPoint:
          type: integer
          minimum: 0
          description: Reorder point threshold
        leadTime:
          type: integer
          description: Lead time in days
          example: 7
        warrantyPeriod:
          type: integer
          description: Warranty period in days
          example: 365
        category:
          type: string
          description: Part category
          example: "Engine"
        subcategory:
          type: string
          description: Part subcategory
          example: "Valves"
        isActive:
          type: boolean
          default: true
          description: Whether the part is active
        barcode:
          type: string
          description: Barcode for the part
        qrCode:
          type: string
          description: QR code for the part
        images:
          type: array
          items:
            type: string
            format: uri
          description: Part images URLs
        documents:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              url:
                type: string
                format: uri
              type:
                type: string
                enum: [manual, specification, certificate, warranty]
        metadata:
          type: object
          additionalProperties: true
          description: Additional metadata
      required:
        - partNumber
        - name
        - partType

  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: api-key

security:
  - ApiKeyAuth: []
