def _create_feature_segment_from_clauses(
    import_request: LaunchDarklyImportRequest,
    clauses: list[Clause],
    project: Project,
    feature: Feature,
    environment: Environment,
    segments_by_ld_key: dict[str, Segment],
    rule_name: str,
) -> list[FeatureState]:
    """
    Create one or multiple feature-specific segment for the given clauses. Note that "segmentMatch" operator
    is not fully supported. If "segmentMatch" is used, we create a feature rule for the given segment(s) instead
    of a feature-specific segment. Thus, we return multiple feature states if there are multiple segments being
    targeted.

    Also note that "segmentMatch" operator is not supported for nested rules. If a nested rule contains
    "segmentMatch", it can't use any other targeting operators. This is because we convert "segmentMatch" into
    a segment specific feature value, thus no further filter can be applied.

    :param clauses: a list of clauses from Launch Darkly's targeting rule.
    :param feature: the feature to target for identities.
    :param segments_by_ld_key: a mapping from Launch Darkly segment key to Segment. Used for "segmentMatch" op.
    :param rule_name: the name of the rule this feature-specific segment is created for.
    :return: a list of FeatureState objects for the newly created feature-specific segments.
    """
    # There is no "segmentMatch" operator in flagsmith, instead we create a targeting rule for that
    # specific segment.
    if "segmentMatch" in [clause["op"] for clause in clauses]:
        return _create_feature_segments_for_segment_match_clauses(
            import_request=import_request,
            clauses=clauses,
            project=project,
            feature=feature,
            environment=environment,
            segments_by_ld_key=segments_by_ld_key,
        )

    # Create a feature specific segment for the rule.
    segment, _ = Segment.live_objects.update_or_create(
        name=rule_name, project=project, feature=feature
    )

    # Create a targeting rule for the new feature-specific segment.
    _create_segment_rule_for_segment(
        import_request=import_request,
        segment=segment,
        clauses=clauses,
    )

    # Tie the feature and segment together.
    feature_segment, _ = FeatureSegment.objects.update_or_create(
        feature=feature,
        segment=segment,
        environment=environment,
    )

    # Enable rules by default. In LD, rules are enabled if the flag is on.
    return [
        FeatureState.objects.update_or_create(
            feature=feature,
            feature_segment=feature_segment,
            environment=environment,
            defaults={"enabled": True},
        )[0]
    ]

    Create one or multiple feature-specific segment for the given clauses. Note that "segmentMatch" operator
    is not fully supported. If "segmentMatch" is used, we create a feature rule for the given segment(s) instead
    of a feature-specific segment. Thus, we return multiple feature states if there are multiple segments being
    targeted.

    Also note that "segmentMatch" operator is not supported for nested rules. If a nested rule contains
    "segmentMatch", it can't use any other targeting operators. This is because we convert "segmentMatch" into
    a segment specific feature value, thus no further filter can be applied.

    :param clauses: a list of clauses from Launch Darkly's targeting rule.
    :param feature: the feature to target for identities.
    :param segments_by_ld_key: a mapping from Launch Darkly segment key to Segment. Used for "segmentMatch" op.
    :param rule_name: the name of the rule this feature-specific segment is created for.
    :return: a list of FeatureState objects for the newly created feature-specific segments.
    
api/integrations/launch_darkly/services.py