openapi: 3.0.0
info:
  title: Asset Unit API
  description: API for managing asset units
  version: 1.0.0
servers:
  - url: https://api.repzo.me/v1
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Asset Unit
    description: Asset unit management operations
paths:
  /asset-unit:
    get:
      tags:
        - Asset Unit
      summary: Get all asset units
      description: Retrieve a list of all asset units with optional filtering and pagination
      parameters:
        - name: page
          in: query
          description: Page number for pagination
          required: false
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: per_page
          in: query
          description: Number of items per page
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
        - name: sort
          in: query
          description: Sort field
          required: false
          schema:
            type: string
        - name: company_namespace
          in: query
          description: Company namespace for filtering
          required: false
          schema:
            type: array
            items:
              type: string
        - name: asset
          in: query
          description: Filter by asset ID
          required: false
          schema:
            type: string
        - name: status
          in: query
          description: Filter by status
          required: false
          schema:
            type: string
            enum: ["active", "maintenance", "retired", "disposed"]
        - name: location
          in: query
          description: Filter by location
          required: false
          schema:
            type: string
        - name: _id
          in: query
          description: Filter by ID
          required: false
          schema:
            type: array
            items:
              type: string
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/AssetUnit"
                  paging:
                    $ref: "#/components/schemas/PagingInfo"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalServerError"
    post:
      tags:
        - Asset Unit
      summary: Create a new asset unit
      description: Create a new asset unit entry
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateAssetUnitRequest"
      responses:
        "201":
          description: Asset unit created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/AssetUnit"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "422":
          $ref: "#/components/responses/ValidationError"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /asset-unit/{id}:
    get:
      tags:
        - Asset Unit
      summary: Get asset unit by ID
      description: Retrieve a specific asset unit by its ID
      parameters:
        - name: id
          in: path
          required: true
          description: Asset unit ID
          schema:
            type: string
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/AssetUnit"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "500":
          $ref: "#/components/responses/InternalServerError"
    patch:
      tags:
        - Asset Unit
      summary: Update asset unit
      description: Update an existing asset unit
      parameters:
        - name: id
          in: path
          required: true
          description: Asset unit ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateAssetUnitRequest"
      responses:
        "200":
          description: Asset unit updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/AssetUnit"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "422":
          $ref: "#/components/responses/ValidationError"
        "500":
          $ref: "#/components/responses/InternalServerError"
    delete:
      tags:
        - Asset Unit
      summary: Delete asset unit
      description: Delete an asset unit by ID
      parameters:
        - name: id
          in: path
          required: true
          description: Asset unit ID
          schema:
            type: string
      responses:
        "200":
          description: Asset unit deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /asset-unit/remove:
    post:
      tags:
        - Asset Unit
      summary: Bulk delete asset units
      description: Delete multiple asset units by their IDs
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ids:
                  type: array
                  items:
                    type: string
                  description: Array of asset unit IDs to delete
              required:
                - ids
      responses:
        "200":
          description: Asset units deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /asset-unit/{id}/status:
    patch:
      tags:
        - Asset Unit
      summary: Update asset unit status
      description: Update the status of an asset unit
      parameters:
        - name: id
          in: path
          required: true
          description: Asset unit ID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum: ["active", "maintenance", "retired", "disposed"]
                  description: New status for the asset unit
                reason:
                  type: string
                  description: Reason for status change
                notes:
                  type: string
                  description: Additional notes
              required:
                - status
      responses:
        "200":
          description: Asset unit status updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/AssetUnit"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "500":
          $ref: "#/components/responses/InternalServerError"
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: "Use format: Bearer {api_key}"
  schemas:
    AssetUnit:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier
          example: "507f1f77bcf86cd799439011"
        asset:
          type: string
          description: Asset ID reference
          example: "507f1f77bcf86cd799439012"
        serial_number:
          type: string
          description: Unique serial number for this unit
          example: "AST-001-2024"
        barcode:
          type: string
          description: Barcode identifier
          example: "123456789012"
        status:
          type: string
          description: Current status of the asset unit
          enum: ["active", "maintenance", "retired", "disposed"]
          example: "active"
        condition:
          type: string
          description: Physical condition of the asset
          enum: ["excellent", "good", "fair", "poor"]
          example: "good"
        location:
          type: string
          description: Current location of the asset unit
          example: "Warehouse A, Section 2"
        assigned_to:
          type: string
          description: User or department assigned to this asset
          example: "507f1f77bcf86cd799439013"
        purchase_date:
          type: string
          format: date
          description: Date when the asset unit was purchased
        warranty_expiry:
          type: string
          format: date
          description: Warranty expiration date
        last_maintenance:
          type: string
          format: date-time
          description: Date of last maintenance
        next_maintenance:
          type: string
          format: date
          description: Date of next scheduled maintenance
        purchase_cost:
          type: number
          format: float
          description: Original purchase cost
          example: 1500.00
        depreciation:
          type: object
          properties:
            method:
              type: string
              enum: ["straight-line", "declining-balance", "sum-of-years"]
            rate:
              type: number
              format: float
            current_value:
              type: number
              format: float
        maintenance_history:
          type: array
          items:
            type: object
            properties:
              date:
                type: string
                format: date-time
              type:
                type: string
                enum: ["routine", "repair", "inspection", "upgrade"]
              description:
                type: string
              cost:
                type: number
                format: float
              performed_by:
                type: string
        notes:
          type: string
          description: Additional notes about the asset unit
        custom_fields:
          type: object
          description: Custom fields for additional data
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the asset unit is disabled
          example: false
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        modifiedAt:
          type: string
          format: date-time
          description: Last modification timestamp
        SVClient:
          type: integer
          description: Client version
        __v:
          type: integer
          description: Document version
      required:
        - asset
        - serial_number
        - status
    CreateAssetUnitRequest:
      type: object
      properties:
        asset:
          type: string
          description: Asset ID reference
          example: "507f1f77bcf86cd799439012"
        serial_number:
          type: string
          description: Unique serial number for this unit
          example: "AST-001-2024"
        barcode:
          type: string
          description: Barcode identifier
        status:
          type: string
          description: Initial status of the asset unit
          enum: ["active", "maintenance", "retired", "disposed"]
          default: "active"
        condition:
          type: string
          description: Physical condition of the asset
          enum: ["excellent", "good", "fair", "poor"]
          default: "good"
        location:
          type: string
          description: Current location of the asset unit
        assigned_to:
          type: string
          description: User or department assigned to this asset
        purchase_date:
          type: string
          format: date
          description: Date when the asset unit was purchased
        warranty_expiry:
          type: string
          format: date
          description: Warranty expiration date
        purchase_cost:
          type: number
          format: float
          description: Original purchase cost
        depreciation:
          type: object
          properties:
            method:
              type: string
              enum: ["straight-line", "declining-balance", "sum-of-years"]
            rate:
              type: number
              format: float
        notes:
          type: string
          description: Additional notes about the asset unit
        custom_fields:
          type: object
          description: Custom fields for additional data
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the asset unit is disabled
          default: false
      required:
        - asset
        - serial_number
    UpdateAssetUnitRequest:
      type: object
      properties:
        serial_number:
          type: string
          description: Unique serial number for this unit
        barcode:
          type: string
          description: Barcode identifier
        status:
          type: string
          description: Status of the asset unit
          enum: ["active", "maintenance", "retired", "disposed"]
        condition:
          type: string
          description: Physical condition of the asset
          enum: ["excellent", "good", "fair", "poor"]
        location:
          type: string
          description: Current location of the asset unit
        assigned_to:
          type: string
          description: User or department assigned to this asset
        purchase_date:
          type: string
          format: date
          description: Date when the asset unit was purchased
        warranty_expiry:
          type: string
          format: date
          description: Warranty expiration date
        last_maintenance:
          type: string
          format: date-time
          description: Date of last maintenance
        next_maintenance:
          type: string
          format: date
          description: Date of next scheduled maintenance
        purchase_cost:
          type: number
          format: float
          description: Original purchase cost
        depreciation:
          type: object
          properties:
            method:
              type: string
              enum: ["straight-line", "declining-balance", "sum-of-years"]
            rate:
              type: number
              format: float
            current_value:
              type: number
              format: float
        notes:
          type: string
          description: Additional notes about the asset unit
        custom_fields:
          type: object
          description: Custom fields for additional data
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespace
        disabled:
          type: boolean
          description: Whether the asset unit is disabled
    PagingInfo:
      type: object
      properties:
        total:
          type: integer
          description: Total number of items
        page:
          type: integer
          description: Current page number
        per_page:
          type: integer
          description: Items per page
        pages:
          type: integer
          description: Total number of pages
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Invalid request parameters"
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Authentication required"
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Insufficient permissions"
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Resource not found"
    ValidationError:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Validation failed"
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Internal server error"
