import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { AppRole } from '../../common/enum/app-role';
import { DatasetProfileComboBoxType } from '../../common/enum/dataset-profile-combo-box-type';
import { DatasetProfileFieldViewStyle } from '../../common/enum/dataset-profile-field-view-style';
import { DatasetStatus } from '../../common/enum/dataset-status';
import { DmpProfileFieldDataType } from '../../common/enum/dmp-profile-field-type';
import { DmpProfileType } from '../../common/enum/dmp-profile-type';
import { DmpStatus } from '../../common/enum/dmp-status';
import { ValidationType } from '../../common/enum/validation-type';
import { DatasetProfileInternalDmpEntitiesType } from '../../common/enum/dataset-profile-internal-dmp-entities-type';
import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order';
import { Role } from '@app/core/common/enum/role';

@Injectable()
export class EnumUtils {
	constructor(private language: TranslateService) { }

	public getEnumValues(T): Array<any> {
		let keys = Object.keys(T);
		keys = keys.slice(0, keys.length / 2);
		const values: Array<Number> = keys.map(Number);
		return values;
	}

	convertFromPrincipalAppRole(status: AppRole): string {
		switch (status) {
			case AppRole.Admin: return this.language.instant('TYPES.APP-ROLE.ADMIN');
			case AppRole.User: return this.language.instant('TYPES.APP-ROLE.USER');
			case AppRole.Manager: return this.language.instant('TYPES.APP-ROLE.MANAGER');
		}
	}

	toDmpProfileFieldDataTypeString(type: DmpProfileFieldDataType): string {
		switch (type) {
			case DmpProfileFieldDataType.Date: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.DATE');
			case DmpProfileFieldDataType.Number: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.NUMBER');
			case DmpProfileFieldDataType.Text: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.TEXT');
			case DmpProfileFieldDataType.ExternalAutocomplete: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.EXTERNAL-AUTOCOMPLETE');
		}
	}

	toDmpProfileTypeString(type: DmpProfileType): string {
		switch (type) {
			case DmpProfileType.Input: return this.language.instant('TYPES.DMP-PROFILE-FIELD.TYPE.INPUT');
		}
	}

	toDatasetStatusString(status: DatasetStatus): string {
		switch (status) {
			case DatasetStatus.Draft: return this.language.instant('TYPES.DATASET-STATUS.DRAFT');
			case DatasetStatus.Finalized: return this.language.instant('TYPES.DATASET-STATUS.FINALISED');
		}
	}

	toDmpStatusString(status: DmpStatus): string {
		switch (status) {
			case DmpStatus.Draft: return this.language.instant('TYPES.DMP.DRAFT');
			case DmpStatus.Finalized: return this.language.instant('TYPES.DMP.FINALISED');
		}
	}

	toDatasetProfileFieldValidationTypeString(status: ValidationType): string {
		switch (status) {
			case ValidationType.None: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VALIDATION-TYPE.NONE');
			case ValidationType.Required: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VALIDATION-TYPE.REQUIRED');
		}
	}

	toDatasetProfileFieldViewStyleString(status: DatasetProfileFieldViewStyle): string {
		switch (status) {
			case DatasetProfileFieldViewStyle.BooleanDecision: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.BOOLEAN-DECISION');
			case DatasetProfileFieldViewStyle.CheckBox: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.CHECKBOX');
			case DatasetProfileFieldViewStyle.ComboBox: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.COMBO-BOX');
			case DatasetProfileFieldViewStyle.InternalDmpEntities: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.INTERNAL-DMP-ENTITIES');
			case DatasetProfileFieldViewStyle.FreeText: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.FREE-TEXT');
			case DatasetProfileFieldViewStyle.RadioBox: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.RADIO-BOX');
			case DatasetProfileFieldViewStyle.TextArea: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.TEXT-AREA');
			case DatasetProfileFieldViewStyle.DatePicker: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.DATE-PICKER');
			case DatasetProfileFieldViewStyle.ExternalDatasets: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.EXTERNAL-DATASETS');
			case DatasetProfileFieldViewStyle.DataRepositories: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.DATA-REPOSITORIES');
			case DatasetProfileFieldViewStyle.Registries: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.REGISTRIES');
			case DatasetProfileFieldViewStyle.Services: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.SERVICES');
			case DatasetProfileFieldViewStyle.Tags: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.TAGS');
			case DatasetProfileFieldViewStyle.Researchers: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.RESEARCHERS');
			case DatasetProfileFieldViewStyle.Organizations: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.ORGANIZATIONS');
			case DatasetProfileFieldViewStyle.DatasetIdentifier: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.DATASET-IDENTIFIER');
			case DatasetProfileFieldViewStyle.Currency: return this.language.instant('TYPES.DATASET-PROFILE-FIELD-VIEW-STYLE.CURRENCY');
		}
	}

	toDatasetProfileComboBoxTypeString(status: DatasetProfileComboBoxType): string {
		switch (status) {
			case DatasetProfileComboBoxType.WordList: return this.language.instant('TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.WORD-LIST');
			case DatasetProfileComboBoxType.Autocomplete: return this.language.instant('TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.AUTOCOMPLETE');
		}
	}

	toDatasetProfileInternalDmpEntitiesTypeString(status: DatasetProfileInternalDmpEntitiesType): string {
		switch (status) {
			case DatasetProfileInternalDmpEntitiesType.Researchers: return this.language.instant('TYPES.DATASET-PROFILE-INTERNAL-DMP-ENTITIES-TYPE.RESEARCHERS');
			case DatasetProfileInternalDmpEntitiesType.Datasets: return this.language.instant('TYPES.DATASET-PROFILE-INTERNAL-DMP-ENTITIES-TYPE.DATASETS');
			case DatasetProfileInternalDmpEntitiesType.Dmps: return this.language.instant('TYPES.DATASET-PROFILE-INTERNAL-DMP-ENTITIES-TYPE.DMPS');
		}
	}

	toRecentActivityOrderString(status: RecentActivityOrder): string {
		switch (status) {
			case RecentActivityOrder.CREATED: return this.language.instant('TYPES.RECENT-ACTIVITY-ORDER.CREATED');
			case RecentActivityOrder.LABEL: return this.language.instant('TYPES.RECENT-ACTIVITY-ORDER.LABEL');
			case RecentActivityOrder.MODIFIED: return this.language.instant('TYPES.RECENT-ACTIVITY-ORDER.MODIFIED');
			case RecentActivityOrder.FINALIZED: return this.language.instant('TYPES.RECENT-ACTIVITY-ORDER.FINALIZED');
			case RecentActivityOrder.PUBLISHED: return this.language.instant('TYPES.RECENT-ACTIVITY-ORDER.PUBLISHED');
			case RecentActivityOrder.DATASETPUBLISHED: return this.language.instant('TYPES.RECENT-ACTIVITY-ORDER.PUBLISHED');
			case RecentActivityOrder.STATUS: return this.language.instant('TYPES.RECENT-ACTIVITY-ORDER.STATUS');
		}
	}

	toRoleString(status: Role): string {
		switch (status) {
			case Role.Owner: return this.language.instant('FACET-SEARCH.ROLE.OWNER');
			case Role.Member: return this.language.instant('FACET-SEARCH.ROLE.MEMBER');
		}
	}
}
