schema:
  type: object
  title: MEL to Constraints Info
  description: Mappings of MEL-Item ATA Code to constraints information
  version: "1.0.0"
  properties:
    ata_chapter:
      description: ATA encoding chapter for the MEL-Item
      title: ATA Chapter
      type: string
      examples:
        - "21"
      coercion: coerce_to_string
      validations:
        pattern:
          regex: "^[0-9]{1,2}$"
        non_empty_string: null
    ata_subchapter:
      description: ATA encoding subchapter for the MEL-Item
      title: ATA Subchapter
      type: string
      examples:
        - "51"
      coercion: coerce_to_string
      validations:
        pattern:
          regex: "^[0-9]{1,2}$"
        non_empty_string: null
    ata_section:
      description: ATA encoding section for the MEL-Item
      title: ATA Section
      type: string
      examples:
        - "01"
      coercion: coerce_to_string
      validations:
        pattern:
          regex: "^[0-9]{1,2}$"
        non_empty_string: null
    ata_item:
      description: ATA Item code
      title: ATA Item
      type: string
      coercion: coerce_to_string
      validations:
        non_empty_string: null
    ac_owner:
      description: Aircraft Owner code
      title: AC Owner
      type: string
      examples:
        - "CX"
      maxLength: 3
      coercion: coerce_to_string
      validations:
        max_length:
          threshold: 3
        non_empty_string: null
    ac_subtype:
      description: Aircraft Subtype code
      title: AC Subtype
      type: string
      examples:
        - "32P"
      maxLength: 10
      coercion: coerce_to_string
      validations:
        max_length:
          threshold: 10
        non_empty_string: null
    constraint_code:
      description: Constraint code associated with the MEL item
      title: Constraint Code
      type: string
      coercion: coerce_to_string
      validations:
        non_empty_string: null
    constraint_description:
      description: Description of the constraint
      title: Constraint Description
      type: string
      coercion: coerce_to_string
    constraint_type:
      description: Type of constraint (e.g., operational, maintenance, regulatory)
      title: Constraint Type
      type: string
      coercion: coerce_to_string
    effective_date:
      description: Date when the constraint becomes effective
      title: Effective Date
      type: string
      format: date-time
      coercion: coerce_to_datetime
    expiry_date:
      description: Date when the constraint expires
      title: Expiry Date
      type: string
      format: date-time
      coercion: coerce_to_nullable_datetime
    severity:
      description: Severity level of the constraint
      title: Severity
      type: string
      enum:
        - "CRITICAL"
        - "HIGH"
        - "MEDIUM"
        - "LOW"
      coercion: coerce_to_string
      validations:
        only_allow:
          allowed_values:
            - "CRITICAL"
            - "HIGH"
            - "MEDIUM"
            - "LOW"
    record_id:
      description: Unique identifier for the record
      title: Record ID
      type: integer
      coercion: coerce_to_integer
      validations:
        greater_than_or_equal_to:
          threshold: 0
    last_updated:
      description: Timestamp of last update
      title: Last Updated
      type: string
      format: date-time
      coercion: coerce_to_datetime
  required:
    - ata_chapter
    - ata_subchapter
    - ata_section
    - ata_item
    - ac_owner
    - ac_subtype
    - constraint_code
    - effective_date
    - record_id

# Top-level coercion and validation rules (parse_contract / create-mixed compatible)
coercion_rules:
  version: "1.0.0"
  rules:
    ata_chapter: coerce_to_string
    ata_subchapter: coerce_to_string
    ata_section: coerce_to_string
    ata_item: coerce_to_string
    ac_owner: coerce_to_string
    ac_subtype: coerce_to_string
    constraint_code: coerce_to_string
    constraint_description: coerce_to_nullable_string
    constraint_type: coerce_to_nullable_string
    effective_date: coerce_to_datetime
    expiry_date: coerce_to_nullable_datetime
    severity: coerce_to_string
    record_id: coerce_to_integer
    last_updated: coerce_to_datetime

validation_rules:
  version: "1.0.0"
  rules:
    ata_chapter:
      pattern:
        regex: "^[0-9]{1,2}$"
      non_empty_string: null
    ata_subchapter:
      pattern:
        regex: "^[0-9]{1,2}$"
      non_empty_string: null
    ata_section:
      pattern:
        regex: "^[0-9]{1,2}$"
      non_empty_string: null
    ata_item:
      non_empty_string: null
    ac_owner:
      max_length:
        threshold: 3
      non_empty_string: null
    ac_subtype:
      max_length:
        threshold: 10
      non_empty_string: null
    constraint_code:
      non_empty_string: null
    constraint_description:
      max_length:
        threshold: 500
    constraint_type:
      max_length:
        threshold: 50
    severity:
      only_allow:
        allowed_values:
          - "CRITICAL"
          - "HIGH"
          - "MEDIUM"
          - "LOW"
    record_id:
      greater_than_or_equal_to:
        threshold: 0

metadata:
  version: "1.0.0"
  description: Mappings of MEL-Item ATA Code to constraints information for operational configuration
  created: '2025-01-15'
  last_updated: '2025-01-15'
  title: MEL to Constraints Info
  status: active
  type: object
  validation_title: MEL to Constraints Info
  created_at: '2025-01-15T00:00:00+00:00'
  updated_at: '2025-01-15T00:00:00+00:00'
  created_by: spicoc@cathaypacific.com
  updated_by: spicoc@cathaypacific.com
  # Ownership and governance_rules must be nested inside metadata
  ownership:
    owner: andrew_baird@cathaypacific.com
    team: data-engineering
    contact: andrew_baird@cathaypacific.com
  governance_rules:
    data_retention:
      days: 2555
      reason: Regulatory compliance for MEL and constraints records
    pii_fields:
      fields: []
    sensitivity: Internal
    access_control:
      read:
        - operations-team
        - data-team
      write:
        - operations-team
  data_feed_association:
    - title: MEL to Constraints Info
      type: Operational
  pulls_from:
    - "NetlineOpsReplica"
  pushes_to:
    - "SCR"
    - "Fleetwise"
  system_sources:
    - "NetlineBase"
  dependencies:
    - "MEL"
    - "Aircraft"
    - "Constraints"
  business_owners:
    - "andrew_baird@cathaypacific.com"
  bu_sme:
    - "lincoln_mak@cathaypacific.com"
  it_application_owners:
    - "ken_tong@cathaypacific.com"
  it_sme:
    - "mimi_chu@cathaypacific.com"
  domain: "IOC"
  data_quality:
    accuracy: 0.0
    monitoring_enabled: false
    sla: null
    total_records: 0
    last_updated: '2024-01-01T00:00:00'
  business_rules:
    validity_period:
      description: effective_date must be before expiry_date if expiry_date is set
      enforced: true
    ata_code_consistency:
      description: ATA chapter, subchapter, section, and item must form a valid ATA code
      enforced: true
  serve:
    api:
      type: GET
      endpoint: "/ioc-de-api/v1/snapshots/operational-configs/mel-to-constraints-info"
      rate_limit: "120/min"
      cache_ttl: 3600
      confluence_page: "https://cathaypacific-prod.atlassian.net/wiki/spaces/DEN/pages/MELToConstraintsInfo"
      params:
        - name: "ata_chapter"
          in: query
          required: false
          description: ATA encoding for the MEL-Item
          schema:
            type: "string"
          example: "21"
        - name: "ata_subchapter"
          in: query
          required: false
          description: ATA encoding for the MEL-Item
          schema:
            type: "string"
          example: "51"
        - name: "ata_section"
          in: query
          required: false
          description: ATA encoding for the MEL-Item
          schema:
            type: "string"
          example: "01"
        - name: "ata_item"
          in: query
          required: false
          description: ATA Item code
          schema:
            type: "string"
        - name: "ac_owner"
          in: query
          required: false
          description: Aircraft Owner code
          schema:
            type: "string"
          example: "CX"
        - name: "ac_subtype"
          in: query
          required: false
          description: Aircraft Subtype code
          schema:
            type: "string"
          example: "32P"
  indexes:
    - cluster: ioc-de-{env}
      database: internal
      collection: mel_to_constraints_info
      indexes:
        - mel_constraints_unique_index:
            ata_chapter: 1
            ata_subchapter: 1
            ata_section: 1
            ata_item: 1
            ac_owner: 1
            ac_subtype: 1
          unique: true
          background: true

versions:
  schema: "1.0.0"
  coercion_rules: "1.0.0"
  validation_rules: "1.0.0"
  metadata: "1.0.0"

