from dataclasses import Field

from apischema.utils import PREFIX

ALIAS_METADATA = f"{PREFIX}alias"
ALIAS_NO_OVERRIDE_METADATA = f"{PREFIX}alias_no_override"
MERGED_METADATA = f"{PREFIX}merged"
CONVERSIONS_METADATA = f"{PREFIX}conversions"
DEFAULT_AS_SET = f"{PREFIX}default_as_set"
DEFAULT_FALLBACK_METADATA = f"{PREFIX}default_fallback"
INIT_VAR_METADATA = f"{PREFIX}init_var"
POST_INIT_METADATA = f"{PREFIX}post_init"
PROPERTIES_METADATA = f"{PREFIX}properties"
REQUIRED_METADATA = f"{PREFIX}required"
SCHEMA_METADATA = f"{PREFIX}schema"
SKIP_METADATA = f"{PREFIX}skip"
VALIDATORS_METADATA = f"{PREFIX}validators"

INCOMPATIBLE_WITH_AGGREGATE = {
    ALIAS_METADATA,
    ALIAS_NO_OVERRIDE_METADATA,
    CONVERSIONS_METADATA,
    REQUIRED_METADATA,
    SCHEMA_METADATA,
    VALIDATORS_METADATA,
}
INCOMPATIBLE_WITH_MERGED = {PROPERTIES_METADATA, *INCOMPATIBLE_WITH_AGGREGATE}
INCOMPATIBLE_WITH_PROPERTIES = {MERGED_METADATA, *INCOMPATIBLE_WITH_AGGREGATE}


def is_aggregate_field(field: Field) -> bool:
    return MERGED_METADATA in field.metadata or PROPERTIES_METADATA in field.metadata
