import json
from datetime import datetime

def parse_pms_data(data, parser_settings):
    date_format = parser_settings["date_format"]
    fields_mapping = parser_settings["fields_mapping"]
    conditions = parser_settings.get("conditions", {})

    parsed_data = []

    for record in data:
        # Применение условий фильтрации
        if conditions:
            for condition_field, expected_value in conditions.items():
                if record.get(condition_field) != expected_value:
                    break
            else:
                # Условие выполнено
                pass
        else:
            # Условие отсутствует
            pass

        # Разбор полей
        parsed_record = {}
        for internal_field, external_field in fields_mapping.items():
            if "." in external_field:  # Например, "guests[0].lastName"
                keys = external_field.split(".")
                value = record
                try:
                    for key in keys:
                        if key.endswith("]"):  # Обработка индексов, например, "guests[0]"
                            key, index = key[:-1].split("[")
                            value = value[key][int(index)]
                        else:
                            value = value[key]
                except (KeyError, IndexError, TypeError):
                    value = None
            else:
                value = record.get(external_field)

            # Преобразование дат
            if "date" in internal_field or "time" in internal_field:
                try:
                    value = datetime.strptime(value, date_format)
                except (ValueError, TypeError):
                    value = None

            parsed_record[internal_field] = value

        parsed_data.append(parsed_record)

    return parsed_data
