{
  "typeName" : "AWS::CustomerProfiles::SegmentDefinition",
  "description" : "A segment definition resource of Amazon Connect Customer Profiles",
  "sourceUrl" : "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-customer-profiles",
  "definitions" : {
    "Tag" : {
      "description" : "A key-value pair to associate with a resource.",
      "type" : "object",
      "properties" : {
        "Key" : {
          "type" : "string",
          "pattern" : "^(?!aws:)[a-zA-Z+-=._:/]+$",
          "description" : "The key name of the tag. You can specify a value that is 1 to 128 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
          "minLength" : 1,
          "maxLength" : 128
        },
        "Value" : {
          "type" : "string",
          "description" : "The value for the tag. You can specify a value that is 0 to 256 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
          "minLength" : 0,
          "maxLength" : 256
        }
      },
      "required" : [ "Key", "Value" ],
      "additionalProperties" : false
    },
    "ConditionOverrides" : {
      "description" : "Overrides the condition block within the original calculated attribute definition.",
      "type" : "object",
      "properties" : {
        "Range" : {
          "$ref" : "#/definitions/RangeOverride"
        }
      },
      "additionalProperties" : false
    },
    "RangeOverride" : {
      "description" : "Defines the range to be applied to the calculated attribute definition.",
      "type" : "object",
      "properties" : {
        "Start" : {
          "description" : "The starting point for this overridden range. Positive numbers indicate how many days in the past data should be included, and negative numbers indicate how many days in the future.",
          "type" : "integer",
          "minimum" : -2147483648,
          "maximum" : 2147483647
        },
        "End" : {
          "description" : "The ending point for this overridden range. Positive numbers indicate how many days in the past data should be included, and negative numbers indicate how many days in the future.",
          "type" : "integer",
          "minimum" : -2147483648,
          "maximum" : 2147483647
        },
        "Unit" : {
          "description" : "The unit to be applied to the range.",
          "type" : "string",
          "enum" : [ "DAYS" ]
        }
      },
      "required" : [ "Start", "Unit" ],
      "additionalProperties" : false
    },
    "AddressDimension" : {
      "description" : "The address based criteria for the segment.",
      "type" : "object",
      "properties" : {
        "City" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "Country" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "County" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "PostalCode" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "Province" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "State" : {
          "$ref" : "#/definitions/ProfileDimension"
        }
      },
      "additionalProperties" : false
    },
    "AttributeDimension" : {
      "description" : "Specifies attribute based criteria for a segment.",
      "type" : "object",
      "properties" : {
        "DimensionType" : {
          "$ref" : "#/definitions/AttributeDimensionType"
        },
        "Values" : {
          "type" : "array",
          "items" : {
            "type" : "string",
            "maxLength" : 255,
            "minLength" : 1
          },
          "insertionOrder" : false,
          "minItems" : 1,
          "maxItems" : 50
        }
      },
      "required" : [ "DimensionType", "Values" ],
      "additionalProperties" : false
    },
    "AttributeDimensionType" : {
      "description" : "The type of segment dimension to use.",
      "type" : "string",
      "enum" : [ "INCLUSIVE", "EXCLUSIVE", "CONTAINS", "BEGINS_WITH", "ENDS_WITH", "BEFORE", "AFTER", "BETWEEN", "NOT_BETWEEN", "ON", "GREATER_THAN", "LESS_THAN", "GREATER_THAN_OR_EQUAL", "LESS_THAN_OR_EQUAL", "EQUAL" ]
    },
    "CalculatedAttributeDimension" : {
      "description" : "Specifies calculated attribute based criteria for a segment.",
      "type" : "object",
      "properties" : {
        "DimensionType" : {
          "$ref" : "#/definitions/AttributeDimensionType"
        },
        "Values" : {
          "type" : "array",
          "items" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 255
          },
          "insertionOrder" : false,
          "minItems" : 1,
          "maxItems" : 50
        },
        "ConditionOverrides" : {
          "$ref" : "#/definitions/ConditionOverrides"
        }
      },
      "required" : [ "DimensionType", "Values" ],
      "additionalProperties" : false
    },
    "CustomAttributes" : {
      "description" : "One or more custom attributes to use as criteria for the segment.",
      "type" : "object",
      "patternProperties" : {
        "^[a-zA-Z_][a-zA-Z_0-9-]*$" : {
          "$ref" : "#/definitions/AttributeDimension"
        }
      },
      "additionalProperties" : false
    },
    "CalculatedCustomAttributes" : {
      "description" : "One or more calculated attributes to use as criteria for the segment.",
      "type" : "object",
      "patternProperties" : {
        "^[a-zA-Z_][a-zA-Z_0-9-]*$" : {
          "$ref" : "#/definitions/CalculatedAttributeDimension"
        }
      },
      "additionalProperties" : false
    },
    "DateDimension" : {
      "description" : "Specifies date based criteria for a segment.",
      "type" : "object",
      "properties" : {
        "DimensionType" : {
          "$ref" : "#/definitions/DateDimensionType"
        },
        "Values" : {
          "type" : "array",
          "items" : {
            "type" : "string"
          },
          "insertionOrder" : false,
          "minItems" : 1,
          "maxItems" : 50
        }
      },
      "required" : [ "DimensionType", "Values" ],
      "additionalProperties" : false
    },
    "DateDimensionType" : {
      "description" : "The type of segment dimension to use for a date dimension.",
      "type" : "string",
      "enum" : [ "BEFORE", "AFTER", "BETWEEN", "NOT_BETWEEN", "ON" ]
    },
    "Dimension" : {
      "description" : "The criteria that define the dimensions for the segment.",
      "oneOf" : [ {
        "type" : "object",
        "title" : "ProfileAttributes",
        "properties" : {
          "ProfileAttributes" : {
            "$ref" : "#/definitions/ProfileAttributes"
          }
        },
        "required" : [ "ProfileAttributes" ],
        "additionalProperties" : false
      }, {
        "type" : "object",
        "title" : "CalculatedAttributes",
        "properties" : {
          "CalculatedAttributes" : {
            "$ref" : "#/definitions/CalculatedCustomAttributes"
          }
        },
        "additionalProperties" : false
      } ]
    },
    "ExtraLengthValueProfileDimension" : {
      "description" : "Specifies criteria for a segment using extended-length string values.",
      "type" : "object",
      "properties" : {
        "DimensionType" : {
          "$ref" : "#/definitions/StringDimensionType"
        },
        "Values" : {
          "type" : "array",
          "items" : {
            "type" : "string",
            "maxLength" : 1000,
            "minLength" : 1
          },
          "insertionOrder" : false,
          "minItems" : 1,
          "maxItems" : 50
        }
      },
      "required" : [ "DimensionType", "Values" ],
      "additionalProperties" : false
    },
    "Group" : {
      "description" : "An array that defines the set of segment criteria to evaluate when handling segment groups for the segment.",
      "type" : "object",
      "properties" : {
        "Dimensions" : {
          "type" : "array",
          "items" : {
            "$ref" : "#/definitions/Dimension"
          }
        },
        "SourceSegments" : {
          "type" : "array",
          "items" : {
            "$ref" : "#/definitions/SourceSegment"
          }
        },
        "SourceType" : {
          "$ref" : "#/definitions/IncludeOptions"
        },
        "Type" : {
          "$ref" : "#/definitions/IncludeOptions"
        }
      },
      "additionalProperties" : false
    },
    "IncludeOptions" : {
      "description" : "Specifies the operator on how to handle multiple groups within the same segment.",
      "type" : "string",
      "enum" : [ "ALL", "ANY", "NONE" ]
    },
    "ProfileAttributes" : {
      "description" : "Specifies the dimension settings within profile attributes for a segment.",
      "type" : "object",
      "properties" : {
        "AccountNumber" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "AdditionalInformation" : {
          "$ref" : "#/definitions/ExtraLengthValueProfileDimension"
        },
        "FirstName" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "LastName" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "MiddleName" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "GenderString" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "PartyTypeString" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "BirthDate" : {
          "$ref" : "#/definitions/DateDimension"
        },
        "PhoneNumber" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "BusinessName" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "BusinessPhoneNumber" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "HomePhoneNumber" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "MobilePhoneNumber" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "EmailAddress" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "PersonalEmailAddress" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "BusinessEmailAddress" : {
          "$ref" : "#/definitions/ProfileDimension"
        },
        "Address" : {
          "$ref" : "#/definitions/AddressDimension"
        },
        "ShippingAddress" : {
          "$ref" : "#/definitions/AddressDimension"
        },
        "MailingAddress" : {
          "$ref" : "#/definitions/AddressDimension"
        },
        "BillingAddress" : {
          "$ref" : "#/definitions/AddressDimension"
        },
        "Attributes" : {
          "$ref" : "#/definitions/CustomAttributes"
        },
        "ProfileType" : {
          "$ref" : "#/definitions/ProfileTypeDimension"
        }
      },
      "additionalProperties" : false
    },
    "ProfileDimension" : {
      "description" : "Specifies profile based criteria for a segment.",
      "type" : "object",
      "properties" : {
        "DimensionType" : {
          "$ref" : "#/definitions/StringDimensionType"
        },
        "Values" : {
          "type" : "array",
          "items" : {
            "type" : "string",
            "maxLength" : 255,
            "minLength" : 1
          },
          "insertionOrder" : false,
          "minItems" : 1,
          "maxItems" : 50
        }
      },
      "required" : [ "DimensionType", "Values" ],
      "additionalProperties" : false
    },
    "ProfileTypeDimension" : {
      "description" : "Specifies profile type based criteria for a segment.",
      "type" : "object",
      "properties" : {
        "DimensionType" : {
          "$ref" : "#/definitions/ProfileTypeDimensionType"
        },
        "Values" : {
          "type" : "array",
          "items" : {
            "$ref" : "#/definitions/ProfileType"
          },
          "insertionOrder" : false,
          "minItems" : 1,
          "maxItems" : 1
        }
      },
      "required" : [ "DimensionType", "Values" ],
      "additionalProperties" : false
    },
    "SegmentGroup" : {
      "type" : "object",
      "properties" : {
        "Groups" : {
          "type" : "array",
          "items" : {
            "$ref" : "#/definitions/Group"
          }
        },
        "Include" : {
          "$ref" : "#/definitions/IncludeOptions"
        }
      },
      "additionalProperties" : false
    },
    "SourceSegment" : {
      "description" : "The base segment to build the segment on.",
      "type" : "object",
      "properties" : {
        "SegmentDefinitionName" : {
          "type" : "string",
          "maxLength" : 64,
          "minLength" : 1,
          "pattern" : "^[a-zA-Z0-9_-]+$"
        }
      },
      "additionalProperties" : false
    },
    "StringDimensionType" : {
      "description" : "The type of segment dimension to use for a string dimension.",
      "type" : "string",
      "enum" : [ "INCLUSIVE", "EXCLUSIVE", "CONTAINS", "BEGINS_WITH", "ENDS_WITH" ]
    },
    "ProfileTypeDimensionType" : {
      "description" : "The type of segment dimension to use for a profile type dimension.",
      "type" : "string",
      "enum" : [ "INCLUSIVE", "EXCLUSIVE" ]
    },
    "ProfileType" : {
      "description" : "The type of profile.",
      "type" : "string",
      "enum" : [ "ACCOUNT_PROFILE", "PROFILE" ]
    },
    "SegmentSort" : {
      "description" : "Defines how segments should be sorted and ordered in the results.",
      "type" : "object",
      "properties" : {
        "Attributes" : {
          "description" : "A list of attributes used to sort the segments and their ordering preferences.",
          "type" : "array",
          "items" : {
            "$ref" : "#/definitions/SortAttribute"
          },
          "minItems" : 1,
          "maxItems" : 10
        }
      },
      "required" : [ "Attributes" ],
      "additionalProperties" : false
    },
    "SortAttribute" : {
      "description" : "Defines the characteristics and rules for sorting by a specific attribute.",
      "type" : "object",
      "properties" : {
        "Name" : {
          "description" : "The name of the attribute to sort by.",
          "type" : "string",
          "minLength" : 1,
          "maxLength" : 255
        },
        "Order" : {
          "$ref" : "#/definitions/SegmentSortOrder"
        },
        "DataType" : {
          "$ref" : "#/definitions/SegmentSortDataType"
        },
        "Type" : {
          "$ref" : "#/definitions/SortAttributeType",
          "default" : "PROFILE"
        }
      },
      "required" : [ "Name", "Order" ],
      "additionalProperties" : false
    },
    "SegmentSortOrder" : {
      "description" : "The sort order for the attribute (ascending or descending).",
      "type" : "string",
      "enum" : [ "ASC", "DESC" ]
    },
    "SegmentSortDataType" : {
      "description" : "The data type of the sort attribute (e.g., string, number, date).",
      "type" : "string",
      "enum" : [ "STRING", "NUMBER", "DATE" ]
    },
    "SortAttributeType" : {
      "description" : "The type of attribute (e.g., profile, calculated).",
      "type" : "string",
      "enum" : [ "PROFILE", "CALCULATED" ]
    }
  },
  "properties" : {
    "CreatedAt" : {
      "description" : "The time of this segment definition got created.",
      "type" : "string",
      "format" : "date-time"
    },
    "Description" : {
      "description" : "The description of the segment definition.",
      "type" : "string",
      "maxLength" : 4000,
      "minLength" : 1
    },
    "DisplayName" : {
      "description" : "The display name of the segment definition.",
      "type" : "string",
      "maxLength" : 255,
      "minLength" : 1
    },
    "DomainName" : {
      "description" : "The unique name of the domain.",
      "type" : "string",
      "maxLength" : 64,
      "minLength" : 1,
      "pattern" : "^[a-zA-Z0-9_-]+$"
    },
    "SegmentDefinitionName" : {
      "description" : "The unique name of the segment definition.",
      "type" : "string",
      "maxLength" : 64,
      "minLength" : 1,
      "pattern" : "^[a-zA-Z0-9_-]+$"
    },
    "SegmentGroups" : {
      "description" : "An array that defines the set of segment criteria to evaluate when handling segment groups for the segment.",
      "$ref" : "#/definitions/SegmentGroup"
    },
    "SegmentSqlQuery" : {
      "description" : "The SQL query that defines the segment criteria.",
      "type" : "string",
      "minLength" : 1,
      "maxLength" : 50000
    },
    "SegmentDefinitionArn" : {
      "description" : "The Amazon Resource Name (ARN) of the segment definition.",
      "type" : "string",
      "maxLength" : 255,
      "minLength" : 1
    },
    "SegmentType" : {
      "description" : "The SQL query that defines the segment criteria.",
      "type" : "string",
      "enum" : [ "CLASSIC", "ENHANCED" ]
    },
    "Tags" : {
      "description" : "The tags used to organize, track, or control access for this resource.",
      "type" : "array",
      "uniqueItems" : true,
      "insertionOrder" : false,
      "items" : {
        "$ref" : "#/definitions/Tag"
      },
      "minItems" : 0,
      "maxItems" : 50
    },
    "SegmentSort" : {
      "description" : "The segment sort configuration for ordering segment results.",
      "$ref" : "#/definitions/SegmentSort"
    }
  },
  "required" : [ "DomainName", "DisplayName", "SegmentDefinitionName" ],
  "readOnlyProperties" : [ "/properties/CreatedAt", "/properties/SegmentDefinitionArn", "/properties/SegmentType" ],
  "createOnlyProperties" : [ "/properties/DomainName", "/properties/SegmentDefinitionName", "/properties/DisplayName", "/properties/SegmentGroups", "/properties/SegmentSqlQuery" ],
  "primaryIdentifier" : [ "/properties/DomainName", "/properties/SegmentDefinitionName" ],
  "handlers" : {
    "create" : {
      "permissions" : [ "profile:CreateSegmentDefinition", "profile:TagResource", "kms:CreateGrant", "kms:DescribeKey", "kms:GetKeyPolicy", "kms:PutKeyPolicy", "kms:ListGrants", "kms:GenerateDataKey" ]
    },
    "read" : {
      "permissions" : [ "profile:GetSegmentDefinition", "profile:ListTagsForResource", "kms:CreateGrant", "kms:DescribeKey", "kms:GetKeyPolicy", "kms:PutKeyPolicy", "kms:ListGrants", "kms:GenerateDataKey" ]
    },
    "update" : {
      "permissions" : [ "profile:GetSegmentDefinition", "profile:ListTagsForResource", "profile:UntagResource", "profile:TagResource", "kms:CreateGrant", "kms:DescribeKey", "kms:GetKeyPolicy", "kms:PutKeyPolicy", "kms:ListGrants", "kms:GenerateDataKey" ]
    },
    "delete" : {
      "permissions" : [ "profile:DeleteSegmentDefinition", "kms:CreateGrant", "kms:DescribeKey", "kms:GetKeyPolicy", "kms:PutKeyPolicy", "kms:ListGrants", "kms:GenerateDataKey" ]
    },
    "list" : {
      "handlerSchema" : {
        "properties" : {
          "DomainName" : {
            "$ref" : "resource-schema.json#/properties/DomainName"
          }
        },
        "required" : [ "DomainName" ]
      },
      "permissions" : [ "profile:ListSegmentDefinitions", "kms:CreateGrant", "kms:DescribeKey", "kms:GetKeyPolicy", "kms:PutKeyPolicy", "kms:ListGrants", "kms:GenerateDataKey" ]
    }
  },
  "tagging" : {
    "taggable" : true,
    "tagOnCreate" : true,
    "tagUpdatable" : true,
    "cloudFormationSystemTags" : true,
    "tagProperty" : "/properties/Tags",
    "permissions" : [ "profile:TagResource", "profile:UntagResource", "profile:ListTagsForResource" ]
  },
  "additionalProperties" : false
}