public IEnumerable <MASchemaType> GetSchemaTypes(IManagementAgentParameters config)
        {
            MASchemaType type = new MASchemaType
            {
                AttributeAdapters = new List <IAttributeAdapter>(),
                Name = SchemaConstants.User,
                AnchorAttributeNames = new[] { "id" },
                SupportsPatch        = true,
            };

            this.BuildBaseSchema(type, config);

            if (config.EnableAdvancedUserAttributes)
            {
                SchemaBuilderUsers.AddGmailSettingsAttributes(type, config);
            }

            yield return(type);

            if (!config.SchemaService.HasSchema(config.CustomerID, SchemaConstants.CustomGoogleAppsSchemaName))
            {
                yield break;
            }

            foreach (string objectType in config.CustomUserObjectClasses)
            {
                type = new MASchemaType
                {
                    AttributeAdapters = new List <IAttributeAdapter>(),
                    Name = objectType,
                    AnchorAttributeNames = new[] { "id" },
                    SupportsPatch        = true,
                };

                this.BuildBaseSchema(type, config);
                SchemaBuilderUsers.AddGmailSettingsAttributes(type, config);

                yield return(type);
            }
        }
        protected MASchemaType BuildBaseSchema(MASchemaType type, IManagementAgentParameters config)
        {
            type.ApiInterface = new ApiInterfaceUser(type, config);

            AdapterPropertyValue orgUnitPath = new AdapterPropertyValue
            {
                AttributeType           = AttributeType.String,
                FieldName               = "orgUnitPath",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                AttributeName           = "orgUnitPath",
                PropertyName            = "OrgUnitPath",
                Api                     = "user",
                SupportsPatch           = true,
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder,
            };

            type.AttributeAdapters.Add(orgUnitPath);

            AdapterPropertyValue includeInGal = new AdapterPropertyValue
            {
                AttributeType           = AttributeType.Boolean,
                FieldName               = "includeInGlobalAddressList",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                AttributeName           = "includeInGlobalAddressList",
                PropertyName            = "IncludeInGlobalAddressList",
                Api                     = "user",
                SupportsPatch           = true,
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder,
                CastForImport           = (i) => i ?? false
            };

            type.AttributeAdapters.Add(includeInGal);

            AdapterPropertyValue suspended = new AdapterPropertyValue
            {
                AttributeType           = AttributeType.Boolean,
                FieldName               = "suspended",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                AttributeName           = "suspended",
                PropertyName            = "Suspended",
                Api                     = "user",
                SupportsPatch           = true,
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder,
                CastForImport           = (i) => i ?? false
            };

            type.AttributeAdapters.Add(suspended);

            AdapterPropertyValue changePasswordAtNextLogin = new AdapterPropertyValue
            {
                AttributeType           = AttributeType.Boolean,
                FieldName               = "changePasswordAtNextLogin",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                AttributeName           = "changePasswordAtNextLogin",
                PropertyName            = "ChangePasswordAtNextLogin",
                Api                     = "user",
                SupportsPatch           = true,
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder,
                CastForImport           = (i) => i ?? false
            };

            type.AttributeAdapters.Add(changePasswordAtNextLogin);

            AdapterPropertyValue ipWhitelisted = new AdapterPropertyValue
            {
                AttributeType = AttributeType.Boolean,
                FieldName     = "ipWhitelisted",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "ipWhitelisted",
                PropertyName  = "IpWhitelisted",
                Api           = "user",
                SupportsPatch = true,
                CastForImport = (i) => i ?? false
            };

            type.AttributeAdapters.Add(ipWhitelisted);

            AdapterPropertyValue id = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "id",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "id",
                PropertyName  = "Id",
                Api           = "user",
                SupportsPatch = true,
                IsAnchor      = true,
            };

            type.AttributeAdapters.Add(id);

            AdapterPropertyValue primaryEmail = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "primaryEmail",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "primaryEmail",
                PropertyName  = "PrimaryEmail",
                Api           = "user",
                SupportsPatch = true,
            };

            type.AttributeAdapters.Add(primaryEmail);

            AdapterPropertyValue isAdmin = new AdapterPropertyValue
            {
                AttributeType           = AttributeType.Boolean,
                FieldName               = "isAdmin",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                AttributeName           = "isAdmin",
                PropertyName            = "IsAdmin",
                Api                     = "usermakeadmin",
                SupportsPatch           = true,
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder,
                CastForImport           = (i) => i ?? false
            };

            type.AttributeAdapters.Add(isAdmin);

            AdapterPropertyValue isDelegatedAdmin = new AdapterPropertyValue
            {
                AttributeType = AttributeType.Boolean,
                FieldName     = "isDelegatedAdmin",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "isDelegatedAdmin",
                PropertyName  = "IsDelegatedAdmin",
                Api           = "user",
                SupportsPatch = true,
                CastForImport = (i) => i ?? false
            };

            type.AttributeAdapters.Add(isDelegatedAdmin);

            AdapterPropertyValue lastLoginTime = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "lastLoginTime",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "lastLoginTime",
                PropertyName  = "LastLoginTime",
                Api           = "user",
                SupportsPatch = true,
            };

            type.AttributeAdapters.Add(lastLoginTime);

            AdapterPropertyValue creationTime = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "creationTime",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "creationTime",
                PropertyName  = "CreationTime",
                Api           = "user",
                SupportsPatch = true,
            };

            type.AttributeAdapters.Add(creationTime);

            AdapterPropertyValue deletionTime = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "deletionTime",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "deletionTime",
                PropertyName  = "DeletionTime",
                Api           = "user",
                SupportsPatch = true,
            };

            type.AttributeAdapters.Add(deletionTime);

            AdapterPropertyValue agreedToTerms = new AdapterPropertyValue
            {
                AttributeType = AttributeType.Boolean,
                FieldName     = "agreedToTerms",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "agreedToTerms",
                PropertyName  = "AgreedToTerms",
                Api           = "user",
                SupportsPatch = true,
                CastForImport = (i) => i ?? false
            };

            type.AttributeAdapters.Add(agreedToTerms);

            AdapterPropertyValue suspensionReason = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "suspensionReason",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "suspensionReason",
                PropertyName  = "SuspensionReason",
                Api           = "user",
                SupportsPatch = true,
            };

            type.AttributeAdapters.Add(suspensionReason);

            AdapterPropertyValue isMailboxSetup = new AdapterPropertyValue
            {
                AttributeType = AttributeType.Boolean,
                FieldName     = "isMailboxSetup",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "isMailboxSetup",
                PropertyName  = "IsMailboxSetup",
                Api           = "user",
                SupportsPatch = true,
                CastForImport = (i) => i ?? false
            };

            type.AttributeAdapters.Add(isMailboxSetup);

            AdapterPropertyValue thumbnailPhotoUrl = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "thumbnailPhotoUrl",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "thumbnailPhotoUrl",
                PropertyName  = "ThumbnailPhotoUrl",
                Api           = "user",
                SupportsPatch = true,
            };

            type.AttributeAdapters.Add(thumbnailPhotoUrl);

            AdapterPropertyValue thumbnailPhotoEtag = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "thumbnailPhotoEtag",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "thumbnailPhotoEtag",
                PropertyName  = "ThumbnailPhotoEtag",
                Api           = "user",
                SupportsPatch = true,
            };

            type.AttributeAdapters.Add(thumbnailPhotoEtag);

            AdapterPropertyValue customerId = new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "customerId",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "customerId",
                PropertyName  = "CustomerId",
                Api           = "user",
                SupportsPatch = true,
            };

            type.AttributeAdapters.Add(customerId);

            SchemaBuilderUsers.AddUserNames(type);
            SchemaBuilderUsers.AddUserNotes(type);
            SchemaBuilderUsers.AddUserWebSites(type, config);
            SchemaBuilderUsers.AddUserAliases(type);
            SchemaBuilderUsers.AddUserPhonesAttributes(type, config);
            SchemaBuilderUsers.AddUserOrganizationsAttributes(type, config);
            SchemaBuilderUsers.AddUserAddresses(type, config);
            SchemaBuilderUsers.AddUserRelations(type, config);
            SchemaBuilderUsers.AddUserExternalIds(type, config);
            SchemaBuilderUsers.AddUserIms(type, config);
            SchemaBuilderUsers.AddUserCustomSchema(type, config);

            return(type);
        }