def get_all_feature_states(
        self,
        traits: list[Trait] | None = None,
        additional_filters: Q | None = None,
    ) -> list[FeatureState]:
        """
        Get all feature states for an identity. This method returns a single flag for
        each feature in the identity's environment's project. The flag returned is the
        correct flag based on the priorities as follows (highest -> lowest):

            1. Identity - flag override for this specific identity
            2. Segment - flag overridden for a segment this identity belongs to
            3. Environment - default value for the environment

        :return: (list) flags for an identity with the correct values based on
            identity / segment priorities
        """
        segments = self.get_segments(traits=traits, overrides_only=True)  # type: ignore[arg-type]

        # define sub queries
        belongs_to_environment_query = Q(environment=self.environment)
        if self.id:
            overridden_for_identity_query = Q(identity=self)
        else:
            # skip identity overrides for transient identities
            overridden_for_identity_query = Q()

        overridden_for_segment_query = Q(
            feature_segment__segment__in=segments,
            feature_segment__environment=self.environment,
        )
        environment_default_query = Q(identity=None, feature_segment=None)

        # define the full query
        full_query = belongs_to_environment_query & (
            overridden_for_identity_query
            | overridden_for_segment_query
            | environment_default_query
        )

        if additional_filters:
            full_query &= additional_filters

        all_flags = get_environment_flags_list(
            environment=self.environment,
            additional_filters=full_query,
            additional_select_related_args=["feature_segment__segment", "identity"],
            additional_prefetch_related_args=[
                Prefetch(
                    "multivariate_feature_state_values",
                    queryset=MultivariateFeatureStateValue.objects.select_related(
                        "multivariate_feature_option"
                    ),
                )
            ],
        )

        # iterate over all the flags and build a dictionary keyed on feature with the highest priority flag
        # for the given identity as the value.
        identity_flags = {}
        for flag in all_flags:
            if flag.feature_id not in identity_flags:
                identity_flags[flag.feature_id] = flag
            else:
                current_flag = identity_flags[flag.feature_id]
                if flag > current_flag:
                    identity_flags[flag.feature_id] = flag

        if self.environment.get_hide_disabled_flags() is True:
            # filter out any flags that are disabled
            return [value for value in identity_flags.values() if value.enabled]

        return list(identity_flags.values())

        Get all feature states for an identity. This method returns a single flag for
        each feature in the identity's environment's project. The flag returned is the
        correct flag based on the priorities as follows (highest -> lowest):

            1. Identity - flag override for this specific identity
            2. Segment - flag overridden for a segment this identity belongs to
            3. Environment - default value for the environment

        :return: (list) flags for an identity with the correct values based on
            identity / segment priorities
        
api/environments/identities/models.py