def _create_segment_rule_for_segment(
    import_request: LaunchDarklyImportRequest,
    segment: Segment,
    clauses: list[Clause],
) -> SegmentRule:
    """
    Create the SegmentRule for the given segment and clauses. This method doesn't handle any feature-specific
    segments. Use "_create_feature_segment_from_clauses" for that.

    :param segment: the segment to create the rule for.
    :param clauses: a list of clauses from Launch Darkly's segment rule. This describes which identities belong
    to the given segment.
    :return: the SegmentRule created for the given segment.
    """

    parent_rule, _ = SegmentRule.objects.get_or_create(
        segment=segment, type=SegmentRule.ALL_RULE
    )
    # TODO: Delete existing rules if parent_rule already exists.

    negated_child = None

    for clause in clauses:
        _property = clause["attribute"]
        operator = _ld_operator_to_flagsmith_operator(clause["op"])
        values = _convert_ld_values(
            [str(value) for value in clause["values"]], clause["op"]
        )

        if operator is not None:
            # Since there is no !X operation in Flagsmith, we wrap negated conditions in a none() rule.
            if clause["negate"] is True:
                # Create a negated child if it doesn't exist.
                if negated_child is None:
                    negated_child = SegmentRule.objects.create(
                        rule=parent_rule, type=SegmentRule.NONE_RULE
                    )

                target_rule = negated_child
            else:
                # Create a new child rule if it doesn't exist. Each child rule is "AND"ed together because
                # parent_rule has type of `ALL`. Also note that each Condition added to this child rule is
                # "OR"ed together. This is also how Launch Darkly works.
                child_rule = SegmentRule.objects.create(
                    rule=parent_rule, type=SegmentRule.ANY_RULE
                )
                target_rule = child_rule

            # Create a condition for each value. Each condition is "OR"ed together.
            for value in values:
                if len(value) > settings.SEGMENT_CONDITION_VALUE_LIMIT:
                    _log_error(
                        import_request=import_request,
                        error_message=(
                            f"Segment condition value '{truncate(value)}' for property '{_property}' exceeds the limit of"
                            f" {settings.SEGMENT_CONDITION_VALUE_LIMIT} characters,"
                            f" skipping for segment '{segment.name}'"
                        ),
                    )
                    continue
                Condition.objects.update_or_create(
                    rule=target_rule,
                    property=_property,
                    value=value,
                    operator=operator,
                    created_with_segment=True,
                )
        else:
            _log_error(
                import_request=import_request,
                error_message=f"Can't map launch darkly operator: {clause['op']}"
                f" skipping for segment: {segment.name}",
            )

    return parent_rule  # type: ignore[no-any-return]

    Create the SegmentRule for the given segment and clauses. This method doesn't handle any feature-specific
    segments. Use "_create_feature_segment_from_clauses" for that.

    :param segment: the segment to create the rule for.
    :param clauses: a list of clauses from Launch Darkly's segment rule. This describes which identities belong
    to the given segment.
    :return: the SegmentRule created for the given segment.
    
api/integrations/launch_darkly/services.py