import { EnumerationType } from './../model/common-model';
import { TranslatedPropertyRules } from './translated-property-rules';

export function validateEnumerationType(entity: EnumerationType, isUniqueCodeRequired: boolean = false) {
    // Enum type is valid if at least one language is filled in
    let rules = TranslatedPropertyRules.anyRequired('denomination')
        .withMessage('common:validation.enumType.denomination')
        .ensure('default').satisfies((value: boolean, enumType: EnumerationType) => {
            // Default is valid IF false OR (true AND active true)
            return value == false || enumType.active;
        }).withMessage('common:validation.enumType.default');

    if (isUniqueCodeRequired) {
        rules.ensure('uniqueCode').required()
    }

    rules.on(entity);
}

export interface EnumerationTypeCategory {
    category: number;
    name: string;
    addName?: string;
    isClosed: boolean;
    route?: string;
}

const enumerationTypeViewTemplate = function (type: string): string {
    return 'digiwall-lib/vm/enumeration-types/enumeration-type-' + type + '-view-model-base.html';
}

export const EnumerationTypeRessourceName = "EnumerationType";
export const EnumerationTypeColorRessourceName = "EnumerationTypeColor";


export const enumerationTypeListViewTemplate = function (): string {
    return enumerationTypeViewTemplate('list');
}
export const enumerationTypeDetailViewTemplate = function (): string {
    return enumerationTypeViewTemplate('detail');
}

