Query: i need my method to be optimized and refactored
```
def normalize_record(record: dict[str, Any], schema: list[bigquery.SchemaField], identifier: str = "",
                     parent_path: str = "") -> dict[str, Any] | None:
    """
    Normalize a record and its nested fields based on the given schema ensuring that required fields are present.

    :param record: The input record to be normalized.
    :param schema: The schema defining the structure and types of the fields in the record.
    :param identifier: The field name used to identify the record for logging purposes.
    :param parent_path: The path to the current field within nested records. Used for logging.
    :return: The normalized record if successful, or None if a required field is missing.
    """
    normalized_record = {}

    for field in schema:
        field_name = field.name
        field_type = field.field_type
        field_mode = field.mode
        value = record.get(field_name)

        current_path = f"{parent_path}.{field_name}" if parent_path else field_name
        log_msg = f"Missing {current_path}" if parent_path else \
            f"Missing required field: {field_name}, {identifier}: {record.get(identifier)}"

        if field_type == "RECORD":
            if field_mode == "REPEATED":
                if value is None:
                    normalized_value = []
                elif isinstance(value, list):
                    normalized_value = []
                    for item in value:
                        if isinstance(item, dict):
                            nested_result = normalize_record(item, field.fields, identifier, current_path)
                            if nested_result is None:
                                logger.warning(log_msg)
                                return None
                            normalized_value.append(nested_result)
                        else:
                            logger.warning(f"Invalid nested record at {current_path}")
                            normalized_value.append(None)
                    normalized_value = normalized_value if normalized_value else []
                else:
                    normalized_value = []
            else:
                if isinstance(value, dict):
                    normalized_value = normalize_record(value, field.fields, identifier, current_path)
                    if normalized_value is None and field_mode == "REQUIRED":
                        logger.warning(log_msg)
                        return None
                else:
                    normalized_value = None
        elif field_mode == "REPEATED":
            if value is None:
                normalized_value = []
            elif isinstance(value, list):
                normalized_value = []
                for item in value:
                    if item is None:
                        logger.warning(log_msg)
                        return None
                    if isinstance(item, dict):
                        nested_result = normalize_record(item, field.fields, identifier, current_path)
                        if nested_result is None:
                            logger.warning(log_msg)
                            return None
                        normalized_value.append(nested_result)
                    else:
                        normalized_value.append(item)
                normalized_value = normalized_value if normalized_value else []
            elif value is not None:
                normalized_value = [value]
            else:
                normalized_value = []
        elif field_type == "DATE":
            # TODO: Simplify this check once 0s no longer occur in the date_last field.
            normalized_value = iso8601_format(value) if value not in [None, "", 0, "0", "null"] else None
        else:
            normalized_value = value
        if field_mode == "REQUIRED" and normalized_value is None:
            logger.warning(log_msg)
            return None

        normalized_record[field_name] = normalized_value

    return normalized_record
```
Subject: computer science
Intent: Other