schema:
  type: object
  title: Sector Constraints Info
  description: Definition of sector constraints info from snapshots with filtering
  version: "1.0.0"
  properties:
    res_model_id:
      description: Resource Model ID (Default is 1, meaning the concerned model for ops)
      title: Resource Model ID
      type: integer
      default: 1
      examples:
        - 1
      coercion: coerce_to_integer
      validations:
        greater_than_or_equal_to:
          threshold: 0
    constraint_code:
      description: Constraint Code
      title: Constraint Code
      type: string
      examples:
        - "DPS NO B747-8F"
      coercion: coerce_to_string
      validations:
        non_empty_string: null
    flight_carrier:
      description: Flight Carrier code
      title: Flight Carrier
      type: string
      examples:
        - "CX"
      maxLength: 3
      coercion: coerce_to_nullable_string
      validations:
        max_length:
          threshold: 3
    flight_number:
      description: Flight Number
      title: Flight Number
      type: integer
      examples:
        - 251
      coercion: coerce_to_nullable_integer
      validations:
        greater_than_or_equal_to:
          threshold: 0
    day_of_origin:
      description: Day of origin (Date component of flight identifier) in ISO format
      title: Day of Origin
      type: string
      format: date-time
      examples:
        - "2035-12-31T00:00:00Z"
      coercion: coerce_to_datetime
      validations:
        non_empty_string: null
    match_aircraft_type:
      description: Match Aircraft Type
      title: Match Aircraft Type
      type: string
      examples:
        - "74N"
      maxLength: 10
      coercion: coerce_to_nullable_string
    constraint_type:
      description: Type of sector constraint
      title: Constraint Type
      type: string
      enum:
        - "AIRPORT_RESTRICTION"
        - "AIRCRAFT_RESTRICTION"
        - "ROUTE_RESTRICTION"
        - "TIME_RESTRICTION"
        - "OTHER"
      coercion: coerce_to_string
      validations:
        only_allow:
          allowed_values:
            - "AIRPORT_RESTRICTION"
            - "AIRCRAFT_RESTRICTION"
            - "ROUTE_RESTRICTION"
            - "TIME_RESTRICTION"
            - "OTHER"
    constraint_description:
      description: Description of the sector constraint
      title: Constraint Description
      type: string
      coercion: coerce_to_nullable_string
    origin_airport:
      description: Origin airport code
      title: Origin Airport
      type: string
      maxLength: 3
      coercion: coerce_to_nullable_string
    destination_airport:
      description: Destination airport code
      title: Destination Airport
      type: string
      maxLength: 3
      coercion: coerce_to_nullable_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:
    - res_model_id
    - constraint_code
    - day_of_origin
    - constraint_type
    - effective_date
    - record_id

metadata:
  version: 1.0.0
  description: Definition of sector constraints info from snapshots with filtering for operational configuration
  created: '2025-01-15'
  last_updated: '2025-01-15'
  title: Sector Constraints Info
  status: active
  type: object
  validation_title: Sector 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:
    owner: andrew_baird@cathaypacific.com
    team: data-engineering
    contact: andrew_baird@cathaypacific.com
  data_feed_association:
    - title: Sector Constraints Info
      type: Operational
  pulls_from:
    - "NetlineOpsReplica"
  pushes_to:
    - "SCR"
    - "Fleetwise"
  system_sources:
    - "NetlineBase"
  dependencies:
    - "Flight"
    - "Aircraft"
    - "Airport"
    - "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'
  governance_rules:
    data_retention:
      days: 2555
      reason: Regulatory compliance for sector constraints records
    pii_fields:
      fields: []
    sensitivity: Internal
    access_control:
      read:
        - operations-team
        - data-team
      write:
        - operations-team
  business_rules:
    validity_period:
      description: effective_date must be before expiry_date if expiry_date is set
      enforced: true
    constraint_consistency:
      description: constraint_code must be unique for a given res_model_id, day_of_origin, and match_aircraft_type
      enforced: true
  serve:
    api:
      type: GET
      endpoint: "/ioc-de-api/v1/snapshots/operational-configs/sector-constraints-info"
      rate_limit: "120/min"
      cache_ttl: 3600
      confluence_page: "https://cathaypacific-prod.atlassian.net/wiki/spaces/DEN/pages/SectorConstraintsInfo"
      params:
        - name: "res_model_id"
          in: query
          required: false
          description: Resource Model ID (Default is 1, meaning the concerned model for ops)
          schema:
            type: integer
          default: 1
          example: 1
        - name: "constraint_code"
          in: query
          required: false
          description: Constraint Code
          schema:
            type: "string"
          example: "DPS NO B747-8F"
        - name: "flight_carrier"
          in: query
          required: false
          description: Flight Carrier code
          schema:
            type: "string"
          example: "CX"
        - name: "flight_number"
          in: query
          required: false
          description: Flight Number
          schema:
            type: integer
          example: 251
        - name: "day_of_origin"
          in: query
          required: true
          description: Day of origin (Date component of flight identifier) in ISO format
          schema:
            type: string
            format: date-time
          example: "2035-12-31T00:00:00Z"
        - name: "match_aircraft_type"
          in: query
          required: false
          description: Match Aircraft Type
          schema:
            type: "string"
          example: "74N"
  indexes:
    - cluster: ioc-de-{env}
      database: internal
      collection: sector_constraints_info
      indexes:
        - sector_constraints_unique_index:
            res_model_id: 1
            constraint_code: 1
            day_of_origin: 1
            match_aircraft_type: 1
          unique: true
          background: true

coercion_rules:
  version: "1.0.0"
  rules:
    res_model_id: coerce_to_integer
    constraint_code: coerce_to_string
    flight_carrier: coerce_to_nullable_string
    flight_number: coerce_to_nullable_integer
    day_of_origin: coerce_to_datetime
    match_aircraft_type: coerce_to_nullable_string
    constraint_type: coerce_to_string
    constraint_description: coerce_to_nullable_string
    origin_airport: coerce_to_nullable_string
    destination_airport: 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:
    res_model_id:
      greater_than_or_equal_to:
        threshold: 0
    constraint_code:
      non_empty_string: null
    flight_carrier:
      max_length:
        threshold: 3
    flight_number:
      greater_than_or_equal_to:
        threshold: 0
    day_of_origin:
      non_empty_string: null
    match_aircraft_type:
      max_length:
        threshold: 10
    constraint_type:
      only_allow:
        allowed_values:
          - "AIRPORT_RESTRICTION"
          - "AIRCRAFT_RESTRICTION"
          - "ROUTE_RESTRICTION"
          - "TIME_RESTRICTION"
          - "OTHER"
    constraint_description:
      max_length:
        threshold: 1000
    origin_airport:
      pattern:
        regex: "^[A-Z]{3}$"
      max_length:
        threshold: 3
    destination_airport:
      pattern:
        regex: "^[A-Z]{3}$"
      max_length:
        threshold: 3
    severity:
      only_allow:
        allowed_values:
          - "CRITICAL"
          - "HIGH"
          - "MEDIUM"
          - "LOW"
    record_id:
      greater_than_or_equal_to:
        threshold: 0

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

