# Register Packs Action
# Validates pack structure and loads components into database

ref: core.register_packs
label: "Register Packs"
description: "Register packs by validating schemas, loading components into database, and copying to permanent storage"
enabled: true
runner_type: shell
entry_point: register_packs.sh

# Parameter delivery: stdin for secure parameter passing (no env vars)
parameter_delivery: stdin
parameter_format: dotenv

# Output format: json (structured data parsing enabled)
output_format: json

# Action parameters schema (StackStorm-style with inline required/secret)
parameters:
  pack_paths:
    type: array
    description: "List of pack directory paths to register"
    items:
      type: string
    minItems: 1
    required: true
  packs_base_dir:
    type: string
    description: "Base directory where packs are permanently stored"
    default: "/opt/attune/packs"
  skip_validation:
    type: boolean
    description: "Skip schema validation of pack components"
    default: false
  skip_tests:
    type: boolean
    description: "Skip running pack tests before registration"
    default: false
  force:
    type: boolean
    description: "Force registration even if pack already exists (will replace)"
    default: false
  api_url:
    type: string
    description: "Attune API URL for registration calls"
    default: "http://localhost:8080"
  api_token:
    type: string
    description: "API authentication token"
    secret: true

# Output schema: describes the JSON structure written to stdout
# Note: stdout/stderr/exit_code are captured automatically by the execution system
output_schema:
  registered_packs:
    type: array
    description: "List of successfully registered packs"
    items:
      type: object
      properties:
        pack_ref:
          type: string
          description: "Pack reference"
        pack_id:
          type: integer
          description: "Database ID of registered pack"
        pack_version:
          type: string
          description: "Pack version"
        storage_path:
          type: string
          description: "Permanent storage path"
        components_registered:
          type: object
          description: "Count of registered components by type"
          properties:
            actions:
              type: integer
              description: "Number of actions registered"
            sensors:
              type: integer
              description: "Number of sensors registered"
            triggers:
              type: integer
              description: "Number of triggers registered"
            rules:
              type: integer
              description: "Number of rules registered"
            workflows:
              type: integer
              description: "Number of workflows registered"
            policies:
              type: integer
              description: "Number of policies registered"
        test_result:
          type: object
          description: "Pack test results (if tests were run)"
          properties:
            status:
              type: string
              description: "Test status"
              enum:
                - passed
                - failed
                - skipped
            total_tests:
              type: integer
              description: "Total number of tests"
            passed:
              type: integer
              description: "Number of passed tests"
            failed:
              type: integer
              description: "Number of failed tests"
        validation_results:
          type: object
          description: "Component validation results"
          properties:
            valid:
              type: boolean
              description: "Whether all components are valid"
            errors:
              type: array
              description: "Validation errors found"
              items:
                type: object
                properties:
                  component_type:
                    type: string
                    description: "Type of component"
                  component_file:
                    type: string
                    description: "File with validation error"
                  error:
                    type: string
                    description: "Error message"
  failed_packs:
    type: array
    description: "List of packs that failed to register"
    items:
      type: object
      properties:
        pack_ref:
          type: string
          description: "Pack reference"
        pack_path:
          type: string
          description: "Pack directory path"
        error:
          type: string
          description: "Error message"
        error_stage:
          type: string
          description: "Stage where error occurred"
          enum:
            - validation
            - testing
            - database_registration
            - file_copy
            - api_call
  summary:
    type: object
    description: "Summary of registration process"
    properties:
      total_packs:
        type: integer
        description: "Total number of packs processed"
      success_count:
        type: integer
        description: "Number of successfully registered packs"
      failure_count:
        type: integer
        description: "Number of failed registrations"
      total_components:
        type: integer
        description: "Total number of components registered"
      duration_ms:
        type: integer
        description: "Total registration time in milliseconds"

# Tags for categorization
tags:
  - pack
  - registration
  - validation
  - installation
  - database
