# Path: src/formpack/utils/array_to_xpath.py
# EXPANDABLE_FIELD_TYPES = [
#     'relevant',
#     'constraint',
#     'calculation',
#     'repeat_count',
# ]
# 
# Path: src/formpack/utils/iterator.py
# def get_first_occurrence(obj):
#     return next(iter(obj))
# 
# Path: src/formpack/utils/replace_aliases.py
# TF_COLUMNS = [
#     'required',
# ]
# KOBO_SPECIFIC_SUB_PATTERN = r'^kobo(–|—)'
# KOBO_SPECIFIC_PREFERRED = 'kobo--'
# SELECT_TYPES = list(selects.keys())
# META_TYPES = [
#     'start',
#     'today',
#     'end',
#     'deviceid',
#     'phone_number',
#     'simserial',
#     'audit',
#     # meta values
#     'username',
#     # reconsider:
#     'phonenumber',
#     'imei',
#     'subscriberid',
#     # geo
#     'start-geopoint',
# ]
# LABEL_OPTIONAL_TYPES = [
#     'calculate',
#     'begin_group',
#     'begin_repeat',
# ] + META_TYPES
# GEO_TYPES = [
#     'gps',
#     'geopoint',
#     'geoshape',
#     'geotrace',
# ]
# MEDIA_TYPES = [
#     'video',
#     'image',
#     'audio',
#     'file',
#     'background-audio',
# ]
# EXTENDED_MEDIA_TYPES = MEDIA_TYPES + ['audit']
# BASIC_TYPES = [
#     # basic entry
#     'text',
#     'integer',
#     'decimal',
#     'email',
#     'barcode',
#     # enter time values
#     'date',
#     'datetime',
#     'time',
#     # prompt to collect geo data
#     'location',
#     # no response
#     'acknowledge',
#     'note',
#     # external data source
#     'xml-external',
#     'csv-external',
#     # other
#     'range',
#     'hidden',
# ]
# MAIN_TYPES = BASIC_TYPES + GEO_TYPES + MEDIA_TYPES
# KNOWN_TYPES = set(
#     list(QUESTION_TYPE_DICT.keys())
#     + list(selects.values())
#     + list(types.values())
# )
# def aliases_to_ordered_dict(_d):
# def _unpack_headers(p_aliases, fp_preferred):
# def kobo_specific_sub(key: str) -> str:
# def dealias_type(type_str, strict=False, allowed_types=None):
# def replace_aliases(content, in_place=False, allowed_types=None):
# def replace_aliases_in_place(content, allowed_types=None):
# 
# Path: src/formpack/constants.py
# MEDIA_TYPES = ('audio', 'image', 'video')
# 
# OR_OTHER_COLUMN = '_or_other'
# 
# TAG_COLUMNS_AND_SEPARATORS = {
#     # Separators are used when flattening tags into a single column. Keys are
#     # column names, values are separators.
#     'hxl': '',
# }
# 
# UNTRANSLATED = None


import re
from collections import OrderedDict
from copy import deepcopy
from typing import (
    Any,
    Dict,
    List,
    Optional,
    Set,
    Tuple,
    Union,
)
from .array_to_xpath import EXPANDABLE_FIELD_TYPES
from .iterator import get_first_occurrence
from .replace_aliases import META_TYPES, selects
from ..constants import (
    MEDIA_TYPES,
    OR_OTHER_COLUMN,
    TAG_COLUMNS_AND_SEPARATORS,
    UNTRANSLATED,
)
    value in the `translated` list was still `x` therefore not being recognized
    as a "known translated" column. This resulted in a mismatch in labels and
    translations and broke the exports and autoreport.
    """
    if not translated_cols:
        return []

    _translated_cols = []
    for col in translated_cols:
        if col in MEDIA_TYPES:
            col = f'media::{col}'
        _translated_cols.append(col)

    return _translated_cols


def _get_special_survey_cols(
    content: Dict[str, List[Any]],
) -> Tuple[OrderedDict, List[str], List[str]]:
    """
    This will extract information about columns in an xlsform with ':'s

    and give the "expand_content" information for parsing these columns.
    Examples--
        'media::image',
        'media::image::English',
        'label::Français',
        'hint::English',
    For more examples, see tests.
    """

# Path: src/formpack/utils/array_to_xpath.py
# EXPANDABLE_FIELD_TYPES = [
#     'relevant',
#     'constraint',
#     'calculation',
#     'repeat_count',
# ]
# 
# Path: src/formpack/utils/iterator.py
# def get_first_occurrence(obj):
#     return next(iter(obj))
# 
# Path: src/formpack/utils/replace_aliases.py
# TF_COLUMNS = [
#     'required',
# ]
# KOBO_SPECIFIC_SUB_PATTERN = r'^kobo(–|—)'
# KOBO_SPECIFIC_PREFERRED = 'kobo--'
# SELECT_TYPES = list(selects.keys())
# META_TYPES = [
#     'start',
#     'today',
#     'end',
#     'deviceid',
#     'phone_number',
#     'simserial',
#     'audit',
#     # meta values
#     'username',
#     # reconsider:
#     'phonenumber',
#     'imei',
#     'subscriberid',
#     # geo
#     'start-geopoint',
# ]
# LABEL_OPTIONAL_TYPES = [
#     'calculate',
#     'begin_group',
#     'begin_repeat',
# ] + META_TYPES
# GEO_TYPES = [
#     'gps',
#     'geopoint',
#     'geoshape',
#     'geotrace',
# ]
# MEDIA_TYPES = [
#     'video',
#     'image',
#     'audio',
#     'file',
#     'background-audio',
# ]
# EXTENDED_MEDIA_TYPES = MEDIA_TYPES + ['audit']
# BASIC_TYPES = [
#     # basic entry
#     'text',
#     'integer',
#     'decimal',
#     'email',
#     'barcode',
#     # enter time values
#     'date',
#     'datetime',
#     'time',
#     # prompt to collect geo data
#     'location',
#     # no response
#     'acknowledge',
#     'note',
#     # external data source
#     'xml-external',
#     'csv-external',
#     # other
#     'range',
#     'hidden',
# ]
# MAIN_TYPES = BASIC_TYPES + GEO_TYPES + MEDIA_TYPES
# KNOWN_TYPES = set(
#     list(QUESTION_TYPE_DICT.keys())
#     + list(selects.values())
#     + list(types.values())
# )
# def aliases_to_ordered_dict(_d):
# def _unpack_headers(p_aliases, fp_preferred):
# def kobo_specific_sub(key: str) -> str:
# def dealias_type(type_str, strict=False, allowed_types=None):
# def replace_aliases(content, in_place=False, allowed_types=None):
# def replace_aliases_in_place(content, allowed_types=None):
# 
# Path: src/formpack/constants.py
# MEDIA_TYPES = ('audio', 'image', 'video')
# 
# OR_OTHER_COLUMN = '_or_other'
# 
# TAG_COLUMNS_AND_SEPARATORS = {
#     # Separators are used when flattening tags into a single column. Keys are
#     # column names, values are separators.
#     'hxl': '',
# }
# 
# UNTRANSLATED = None


# Path: src/formpack/utils/expand_content.py
import re
from collections import OrderedDict
from copy import deepcopy
from typing import (
    Any,
    Dict,
    List,
    Optional,
    Set,
    Tuple,
    Union,
)
from .array_to_xpath import EXPANDABLE_FIELD_TYPES
from .iterator import get_first_occurrence
from .replace_aliases import META_TYPES, selects
from ..constants import (
    MEDIA_TYPES,
    OR_OTHER_COLUMN,
    TAG_COLUMNS_AND_SEPARATORS,
    UNTRANSLATED,
)

    value in the `translated` list was still `x` therefore not being recognized
    as a "known translated" column. This resulted in a mismatch in labels and
    translations and broke the exports and autoreport.
    """
    if not translated_cols:
        return []

    _translated_cols = []
    for col in translated_cols:
        if col in MEDIA_TYPES:
            col = f'media::{col}'
        _translated_cols.append(col)

    return _translated_cols


def _get_special_survey_cols(
    content: Dict[str, List[Any]],
) -> Tuple[OrderedDict, List[str], List[str]]:
    """
    This will extract information about columns in an xlsform with ':'s

    and give the "expand_content" information for parsing these columns.
    Examples--
        'media::image',
        'media::image::English',
        'label::Français',
        'hint::English',
    For more examples, see tests.
    """

    RE_MEDIA_TYPES = '|'.join(MEDIA_TYPES)