---
inputType: "CA10__CaAwsBucket__c"
testData:
  - file: "test-data.json"
importExtracts:
  - file: "/types/CA10__CaAwsBucket__c/object.extracts.yaml"
conditions:
  - status: "INAPPLICABLE"
    currentStateMessage: "The bucket doesn't store objects in Intelligent Tiering."
    check:
      AND:
        args:
          - IS_EMPTY:
              arg:
                EXTRACT: "CA10__intelligentTieringStorageGb__c"
          - IS_EMPTY:
              arg:
                EXTRACT: "caJsonFrom__lifecycleRulesJson__c"
  - status: "INAPPLICABLE"
    currentStateMessage: "The bucket doesn't store objects in Intelligent Tiering."
    check:
      AND:
        args:
          - IS_EMPTY:
              arg:
                EXTRACT: "CA10__intelligentTieringStorageGb__c"
          # returns true if there are no active lifecycle rules that move objects to INTELLIGENT_TIERING
          - IS_EQUAL:
              left:
                JSON_QUERY_NUMBER:
                  arg: 
                    EXTRACT: "caJsonFrom__lifecycleRulesJson__c"
                  expression: "length([?status=='Enabled'].transitions[] | [?storageClassAsString=='INTELLIGENT_TIERING'])"
                  undeterminedIf: 
                    evaluationError: "The JSON query has failed."
                    resultTypeMismatch: "The JSON query did not return a boolean."
              right:
                NUMBER: 0.0 
  - status: "INCOMPLIANT"
    currentStateMessage: "The bucket doesn't have an Intelligent Tiering configuration."
    remediationMessage: "Consider creating an S3 Intelligent Tiering configuration for the bucket."
    check:
      IS_EMPTY:
        arg:
          EXTRACT: "caJsonFrom__intelligentTieringConfigurationsJson__c"
  - status: "INCOMPLIANT"
    currentStateMessage: "The bucket doesn't have an Intelligent Tiering configuration."
    remediationMessage: "Consider creating an S3 Intelligent Tiering configuration for the bucket."
    check:
      IS_EQUAL:
        left:
          JSON_QUERY_NUMBER:
            arg:
              EXTRACT: "caJsonFrom__intelligentTieringConfigurationsJson__c"
            expression: "length(@)"
            undeterminedIf:
              evaluationError: "The JSON query has failed."
              resultTypeMismatch: "The JSON query did not return number type."
        right:
          NUMBER: 0.0 
  - status: "INCOMPLIANT"
    currentStateMessage: "The bucket Intelligent Tiering configuration is disabled."
    remediationMessage: "Consider enabling an S3 Intelligent Tiering configuration for the bucket."
    check:
      IS_EQUAL:
        left:
          JSON_QUERY_NUMBER:
            arg:
              EXTRACT: "caJsonFrom__intelligentTieringConfigurationsJson__c"
            expression: "length([?status=='Enabled'])"
            undeterminedIf:
              evaluationError: "The JSON query has failed."
              resultTypeMismatch: "The JSON query did not return number type."
        right:
          NUMBER: 0.0 
otherwise:
  status: "COMPLIANT"
  currentStateMessage: "The bucket has an active Intelligent Tiering configuration."