import { MappingEmpty } from '../../../mapping/empty';
import { MappingIcon } from '../../../mapping/icon';
import { MappingSpinner } from '../../../mapping/spinner';
import { MappingText } from '../../../mapping/text';
import { TableColumnEnumBaseValidator, enumBaseValidityFlagNames } from '../../enum-base/models/table-column-enum-base-validator';
const mappingColumnValidityFlagNames = [
    ...enumBaseValidityFlagNames,
    'unsupportedMappingType',
    'invalidIconName',
    'missingTextValue'
];
/**
 * Validator for TableColumnMapping
 */
export class TableColumnMappingValidator extends TableColumnEnumBaseValidator {
    constructor() {
        super(mappingColumnValidityFlagNames);
    }
    static isIconMappingElement(mapping) {
        return mapping instanceof MappingIcon;
    }
    static isSupportedMappingElement(mapping) {
        return (mapping instanceof MappingIcon
            || mapping instanceof MappingSpinner
            || mapping instanceof MappingText
            || mapping instanceof MappingEmpty);
    }
    validate(mappings, keyType) {
        super.validate(mappings, keyType);
        this.validateMappingTypes(mappings);
        this.validateIconNames(mappings);
        this.validateNoMissingText(mappings);
    }
    validateIconNames(mappings) {
        const invalid = mappings
            .filter(TableColumnMappingValidator.isIconMappingElement)
            .some(mappingIcon => mappingIcon.resolvedIcon === undefined);
        this.setConditionValue('invalidIconName', invalid);
    }
    validateNoMissingText(mappings) {
        const invalid = mappings
            .filter(TableColumnMappingValidator.isSupportedMappingElement)
            .some(mapping => mapping.text === undefined);
        this.setConditionValue('missingTextValue', invalid);
    }
    validateMappingTypes(mappings) {
        const valid = mappings.every(TableColumnMappingValidator.isSupportedMappingElement);
        this.setConditionValue('unsupportedMappingType', !valid);
    }
}
//# sourceMappingURL=table-column-mapping-validator.js.map