[Autofill] Add AttributeType::field_subtypes()

This CL adds AttributeType::field_subtypes(), which will be needed
for issue 422563282 to detect for a given AttributeType whether it
can store a FieldType. For example, we'll need to figure out that
AttributeType(kPassportName) can store NAME_FIRST.

Bug: 422716363, 422563282
Change-Id: Ie5a78ba7c43b9c6b895d39248f78f4caebfd7bea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6623995
Reviewed-by: Jan Keitel <jkeitel@google.com>
Commit-Queue: Christoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/main@{#1470055}
diff --git a/components/autofill/core/browser/data_model/autofill_ai/entity_type.h b/components/autofill/core/browser/data_model/autofill_ai/entity_type.h
index 35da794..a783f05 100644
--- a/components/autofill/core/browser/data_model/autofill_ai/entity_type.h
+++ b/components/autofill/core/browser/data_model/autofill_ai/entity_type.h
@@ -75,8 +75,15 @@
 
   constexpr DataType data_type() const;
 
-  // Maps this AttributeType to the corresponding Autofill AI `FieldType`.
+  // There are three kinds of associated FieldTypes of this AttributeTypes:
+  // - The main field type is the one that best describes the full attribute.
+  //   Except for name fields, FromFieldType(field_type()) == field_type().
+  // - The subtypes include the main type plus more fine-granular ones, such as
+  //   NAME_FIRST.
+  // - The stored types is are the ones that may be physically stored in the
+  //   database. Those are in EntityInstance::GetDatabaseStoredTypes().
   constexpr FieldType field_type() const;
+  constexpr FieldTypeSet field_subtypes() const;
 
   // Returns whether the attribute should be obfuscated in preview and
   // suggestion labels.
@@ -177,6 +184,13 @@
   NOTREACHED();
 }
 
+constexpr FieldTypeSet AttributeType::field_subtypes() const {
+  if (data_type() == DataType::kName) {
+    return FieldTypesOfGroup(FieldTypeGroup::kName);
+  }
+  return {field_type()};
+}
+
 template <>
 struct DenseSetTraits<AttributeType> {
   using T = AttributeType;
diff --git a/components/autofill/core/browser/data_model/autofill_ai/entity_type_unittest.cc b/components/autofill/core/browser/data_model/autofill_ai/entity_type_unittest.cc
index 6cc17cd..b69ce04 100644
--- a/components/autofill/core/browser/data_model/autofill_ai/entity_type_unittest.cc
+++ b/components/autofill/core/browser/data_model/autofill_ai/entity_type_unittest.cc
@@ -18,6 +18,13 @@
   AttributeType a = AttributeType(AttributeTypeName::kPassportName);
   EXPECT_EQ(a.entity_type(), EntityType(EntityTypeName::kPassport));
   EXPECT_EQ(a.field_type(), PASSPORT_NAME_TAG);
+  EXPECT_THAT(a.field_subtypes(),
+              UnorderedElementsAre(
+                  NAME_HONORIFIC_PREFIX, NAME_FIRST, NAME_MIDDLE, NAME_LAST,
+                  NAME_LAST_PREFIX, NAME_LAST_CORE, NAME_LAST_FIRST,
+                  NAME_LAST_SECOND, NAME_LAST_CONJUNCTION, NAME_MIDDLE_INITIAL,
+                  NAME_FULL, NAME_SUFFIX, ALTERNATIVE_FAMILY_NAME,
+                  ALTERNATIVE_GIVEN_NAME, ALTERNATIVE_FULL_NAME));
   EXPECT_EQ(a, AttributeType::FromFieldType(PASSPORT_NAME_TAG));
 }