/*
 * Copyright © 2016-2018 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
export default angular.module('thingsboard.types', [])
    .constant('types',
        {
            serverErrorCode: {
                general: 2,
                authentication: 10,
                jwtTokenExpired: 11,
                permissionDenied: 20,
                invalidArguments: 30,
                badRequestParams: 31,
                itemNotFound: 32
            },
            entryPoints: {
                login: "/api/auth/login",
                tokenRefresh: "/api/auth/token",
                nonTokenBased: "/api/noauth"
            },
            id: {
                nullUid: "13814000-1dd2-11b2-8080-808080808080",
            },
            aggregation: {
                min: {
                    value: "MIN",
                    name: "aggregation.min"
                },
                max: {
                    value: "MAX",
                    name: "aggregation.max"
                },
                avg: {
                    value: "AVG",
                    name: "aggregation.avg"
                },
                sum: {
                    value: "SUM",
                    name: "aggregation.sum"
                },
                count: {
                    value: "COUNT",
                    name: "aggregation.count"
                },
                none: {
                    value: "NONE",
                    name: "aggregation.none"
                }
            },
            alarmFields: {
                createdTime: {
                    keyName: 'createdTime',
                    value: "createdTime",
                    name: "alarm.created-time",
                    time: true
                },
                startTime: {
                    keyName: 'startTime',
                    value: "startTs",
                    name: "alarm.start-time",
                    time: true
                },
                endTime: {
                    keyName: 'endTime',
                    value: "endTs",
                    name: "alarm.end-time",
                    time: true
                },
                ackTime: {
                    keyName: 'ackTime',
                    value: "ackTs",
                    name: "alarm.ack-time",
                    time: true
                },
                clearTime: {
                    keyName: 'clearTime',
                    value: "clearTs",
                    name: "alarm.clear-time",
                    time: true
                },
                originator: {
                    keyName: 'originator',
                    value: "originatorName",
                    name: "alarm.originator"
                },
                originatorType: {
                    keyName: 'originatorType',
                    value: "originator.entityType",
                    name: "alarm.originator-type"
                },
                type: {
                    keyName: 'type',
                    value: "type",
                    name: "alarm.type"
                },
                severity: {
                    keyName: 'severity',
                    value: "severity",
                    name: "alarm.severity"
                },
                status: {
                    keyName: 'status',
                    value: "status",
                    name: "alarm.status"
                }
            },
            alarmStatus: {
                activeUnack: "ACTIVE_UNACK",
                activeAck: "ACTIVE_ACK",
                clearedUnack: "CLEARED_UNACK",
                clearedAck: "CLEARED_ACK"
            },
            alarmSearchStatus: {
                any: "ANY",
                active: "ACTIVE",
                cleared: "CLEARED",
                ack: "ACK",
                unack: "UNACK"
            },
            alarmSeverity: {
                "CRITICAL": {
                    name: "alarm.severity-critical",
                    class: "tb-critical",
                    color: "red"
                },
                "MAJOR": {
                    name: "alarm.severity-major",
                    class: "tb-major",
                    color: "orange"
                },
                "MINOR": {
                    name: "alarm.severity-minor",
                    class: "tb-minor",
                    color: "#ffca3d"
                },
                "WARNING": {
                    name: "alarm.severity-warning",
                    class: "tb-warning",
                    color: "#abab00"
                },
                "INDETERMINATE": {
                    name: "alarm.severity-indeterminate",
                    class: "tb-indeterminate",
                    color: "green"
                }
            },
            auditLogActionType: {
                "ADDED": {
                    name: "audit-log.type-added"
                },
                "DELETED": {
                    name: "audit-log.type-deleted"
                },
                "UPDATED": {
                    name: "audit-log.type-updated"
                },
                "ATTRIBUTES_UPDATED": {
                    name: "audit-log.type-attributes-updated"
                },
                "ATTRIBUTES_DELETED": {
                    name: "audit-log.type-attributes-deleted"
                },
                "RPC_CALL": {
                    name: "audit-log.type-rpc-call"
                },
                "CREDENTIALS_UPDATED": {
                    name: "audit-log.type-credentials-updated"
                },
                "ASSIGNED_TO_CUSTOMER": {
                    name: "audit-log.type-assigned-to-customer"
                },
                "UNASSIGNED_FROM_CUSTOMER": {
                    name: "audit-log.type-unassigned-from-customer"
                },
                "ACTIVATED": {
                    name: "audit-log.type-activated"
                },
                "SUSPENDED": {
                    name: "audit-log.type-suspended"
                },
                "CREDENTIALS_READ": {
                    name: "audit-log.type-credentials-read"
                },
                "ATTRIBUTES_READ": {
                    name: "audit-log.type-attributes-read"
                }
            },
            auditLogActionStatus: {
                "SUCCESS": {
                    value: "SUCCESS",
                    name: "audit-log.status-success"
                },
                "FAILURE": {
                    value: "FAILURE",
                    name: "audit-log.status-failure"
                }
            },
            auditLogMode: {
                tenant: "tenant",
                entity: "entity",
                user: "user",
                customer: "customer"
            },
            aliasFilterType: {
                singleEntity: {
                    value: 'singleEntity',
                    name: 'alias.filter-type-single-entity'
                },
                entityList: {
                    value: 'entityList',
                    name: 'alias.filter-type-entity-list'
                },
                entityName: {
                    value: 'entityName',
                    name: 'alias.filter-type-entity-name'
                },
                stateEntity: {
                    value: 'stateEntity',
                    name: 'alias.filter-type-state-entity'
                },
                assetType: {
                    value: 'assetType',
                    name: 'alias.filter-type-asset-type'
                },
                deviceType: {
                    value: 'deviceType',
                    name: 'alias.filter-type-device-type'
                },
                relationsQuery: {
                    value: 'relationsQuery',
                    name: 'alias.filter-type-relations-query'
                },
                assetSearchQuery: {
                    value: 'assetSearchQuery',
                    name: 'alias.filter-type-asset-search-query'
                },
                deviceSearchQuery: {
                    value: 'deviceSearchQuery',
                    name: 'alias.filter-type-device-search-query'
                }
            },
            position: {
                top: {
                    value: "top",
                    name: "position.top"
                },
                bottom: {
                    value: "bottom",
                    name: "position.bottom"
                },
                left: {
                    value: "left",
                    name: "position.left"
                },
                right: {
                    value: "right",
                    name: "position.right"
                }
            },
            datasourceType: {
                function: "function",
                entity: "entity"
            },
            dataKeyType: {
                timeseries: "timeseries",
                attribute: "attribute",
                function: "function",
                alarm: "alarm"
            },
            contentType: {
                "JSON": {
                    value: "JSON",
                    name: "content-type.json",
                    code: "json"
                },
                "TEXT": {
                    value: "TEXT",
                    name: "content-type.text",
                    code: "text"
                },
                "BINARY": {
                    value: "BINARY",
                    name: "content-type.binary",
                    code: "text"
                }
            },
            componentType: {
                enrichment: "ENRICHMENT",
                filter: "FILTER",
                transformation: "TRANSFORMATION",
                action: "ACTION",
                external: "EXTERNAL"
            },
            entityType: {
                device: "DEVICE",
                asset: "ASSET",
                tenant: "TENANT",
                customer: "CUSTOMER",
                user: "USER",
                dashboard: "DASHBOARD",
                alarm: "ALARM",
                rulechain: "RULE_CHAIN",
                rulenode: "RULE_NODE"
            },
            aliasEntityType: {
                current_customer: "CURRENT_CUSTOMER"
            },
            entityTypeTranslations: {
                "DEVICE": {
                    type: 'entity.type-device',
                    typePlural: 'entity.type-devices',
                    list: 'entity.list-of-devices',
                    nameStartsWith: 'entity.device-name-starts-with'
                },
                "ASSET": {
                    type: 'entity.type-asset',
                    typePlural: 'entity.type-assets',
                    list: 'entity.list-of-assets',
                    nameStartsWith: 'entity.asset-name-starts-with'
                },
                "TENANT": {
                    type: 'entity.type-tenant',
                    typePlural: 'entity.type-tenants',
                    list: 'entity.list-of-tenants',
                    nameStartsWith: 'entity.tenant-name-starts-with'
                },
                "CUSTOMER": {
                    type: 'entity.type-customer',
                    typePlural: 'entity.type-customers',
                    list: 'entity.list-of-customers',
                    nameStartsWith: 'entity.customer-name-starts-with'
                },
                "USER": {
                    type: 'entity.type-user',
                    typePlural: 'entity.type-users',
                    list: 'entity.list-of-users',
                    nameStartsWith: 'entity.user-name-starts-with'
                },
                "DASHBOARD": {
                    type: 'entity.type-dashboard',
                    typePlural: 'entity.type-dashboards',
                    list: 'entity.list-of-dashboards',
                    nameStartsWith: 'entity.dashboard-name-starts-with'
                },
                "ALARM": {
                    type: 'entity.type-alarm',
                    typePlural: 'entity.type-alarms',
                    list: 'entity.list-of-alarms',
                    nameStartsWith: 'entity.alarm-name-starts-with'
                },
                "RULE_CHAIN": {
                    type: 'entity.type-rulechain',
                    typePlural: 'entity.type-rulechains',
                    list: 'entity.list-of-rulechains',
                    nameStartsWith: 'entity.rulechain-name-starts-with'
                },
                "CURRENT_CUSTOMER": {
                    type: 'entity.type-current-customer',
                    list: 'entity.type-current-customer'
                }
            },
            entitySearchDirection: {
                from: "FROM",
                to: "TO"
            },
            entityRelationType: {
                contains: "Contains",
                manages: "Manages"
            },
            eventType: {
                error: {
                    value: "ERROR",
                    name: "event.type-error"
                },
                lcEvent: {
                    value: "LC_EVENT",
                    name: "event.type-lc-event"
                },
                stats: {
                    value: "STATS",
                    name: "event.type-stats"
                }
            },
            debugEventType: {
                debugRuleNode: {
                    value: "DEBUG_RULE_NODE",
                    name: "event.type-debug-rule-node"
                },
                debugRuleChain: {
                    value: "DEBUG_RULE_CHAIN",
                    name: "event.type-debug-rule-chain"
                }
            },
            extensionType: {
                http: "HTTP",
                mqtt: "MQTT",
                opc: "OPC UA",
                modbus: "MODBUS"
            },
            extensionValueType: {
                string: 'value.string',
                long: 'value.long',
                double: 'value.double',
                boolean: 'value.boolean'
            },
            extensionTransformerType: {
                toDouble: 'extension.to-double',
                custom: 'extension.custom'
            },
            mqttConverterTypes: {
                json: 'extension.converter-json',
                custom: 'extension.custom'
            },
            mqttCredentialTypes: {
                anonymous:  {
                    value: "anonymous",
                    name: "extension.anonymous"
                },
                basic: {
                    value: "basic",
                    name: "extension.basic"
                },
                pem: {
                    value: "cert.PEM",
                    name: "extension.pem"
                }
            },
            extensionOpcSecurityTypes: {
                Basic128Rsa15: "Basic128Rsa15",
                Basic256: "Basic256",
                Basic256Sha256: "Basic256Sha256",
                None: "None"
            },
            extensionIdentityType: {
                anonymous: "extension.anonymous",
                username: "extension.username"
            },
            extensionKeystoreType: {
                PKCS12: "PKCS12",
                JKS: "JKS"
            },
            extensionModbusFunctionCodes: {
                1: "Read Coils (1)",
                2: "Read Discrete Inputs (2)",
                3: "Read Multiple Holding Registers (3)",
                4: "Read Input Registers (4)"
            },
            extensionModbusTransports: {
                tcp: "TCP",
                udp: "UDP",
                rtu: "RTU"
            },
            extensionModbusRtuParities: {
                none: "none",
                even: "even",
                odd: "odd"
            },
            extensionModbusRtuEncodings: {
                ascii: "ascii",
                rtu: "rtu"
            },
            latestTelemetry: {
                value: "LATEST_TELEMETRY",
                name: "attribute.scope-latest-telemetry",
                clientSide: true
            },
            attributesScope: {
                client: {
                    value: "CLIENT_SCOPE",
                    name: "attribute.scope-client",
                    clientSide: true
                },
                server: {
                    value: "SERVER_SCOPE",
                    name: "attribute.scope-server",
                    clientSide: false
                },
                shared: {
                    value: "SHARED_SCOPE",
                    name: "attribute.scope-shared",
                    clientSide: false
                }
            },
            ruleNodeTypeComponentTypes: ["FILTER", "ENRICHMENT", "TRANSFORMATION", "ACTION", "EXTERNAL"],
            ruleChainNodeComponent: {
                type: 'RULE_CHAIN',
                name: 'rule chain',
                clazz: 'tb.internal.RuleChain',
                configurationDescriptor: {
                    nodeDefinition: {
                        description: "",
                        details: "Forwards incoming messages to specified Rule Chain",
                        inEnabled: true,
                        outEnabled: false,
                        relationTypes: [],
                        customRelations: false,
                        defaultConfiguration: {}
                    }
                }
            },
            inputNodeComponent: {
                type: 'INPUT',
                name: 'Input',
                clazz: 'tb.internal.Input'
            },
            ruleNodeType: {
                FILTER: {
                    value: "FILTER",
                    name: "rulenode.type-filter",
                    details: "rulenode.type-filter-details",
                    nodeClass: "tb-filter-type",
                    icon: "filter_list"
                },
                ENRICHMENT: {
                    value: "ENRICHMENT",
                    name: "rulenode.type-enrichment",
                    details: "rulenode.type-enrichment-details",
                    nodeClass: "tb-enrichment-type",
                    icon: "playlist_add"
                },
                TRANSFORMATION: {
                    value: "TRANSFORMATION",
                    name: "rulenode.type-transformation",
                    details: "rulenode.type-transformation-details",
                    nodeClass: "tb-transformation-type",
                    icon: "transform"
                },
                ACTION: {
                    value: "ACTION",
                    name: "rulenode.type-action",
                    details: "rulenode.type-action-details",
                    nodeClass: "tb-action-type",
                    icon: "flash_on"
                },
                EXTERNAL: {
                    value: "EXTERNAL",
                    name: "rulenode.type-external",
                    details: "rulenode.type-external-details",
                    nodeClass: "tb-external-type",
                    icon: "cloud_upload"
                },
                RULE_CHAIN: {
                    value: "RULE_CHAIN",
                    name: "rulenode.type-rule-chain",
                    details: "rulenode.type-rule-chain-details",
                    nodeClass: "tb-rule-chain-type",
                    icon: "settings_ethernet"
                },
                INPUT: {
                    value: "INPUT",
                    name: "rulenode.type-input",
                    details: "rulenode.type-input-details",
                    nodeClass: "tb-input-type",
                    icon: "input",
                    special: true
                }
            },
            valueType: {
                string: {
                    value: "string",
                    name: "value.string",
                    icon: "mdi:format-text"
                },
                integer: {
                    value: "integer",
                    name: "value.integer",
                    icon: "mdi:numeric"
                },
                double: {
                    value: "double",
                    name: "value.double",
                    icon: "mdi:numeric"
                },
                boolean: {
                    value: "boolean",
                    name: "value.boolean",
                    icon: "mdi:checkbox-marked-outline"
                }
            },
            widgetType: {
                timeseries: {
                    value: "timeseries",
                    name: "widget.timeseries",
                    template: {
                        bundleAlias: "charts",
                        alias: "basic_timeseries"
                    }
                },
                latest: {
                    value: "latest",
                    name: "widget.latest-values",
                    template: {
                        bundleAlias: "cards",
                        alias: "attributes_card"
                    }
                },
                rpc: {
                    value: "rpc",
                    name: "widget.rpc",
                    template: {
                        bundleAlias: "gpio_widgets",
                        alias: "basic_gpio_control"
                    }
                },
                alarm: {
                    value: "alarm",
                    name: "widget.alarm",
                    template: {
                        bundleAlias: "alarm_widgets",
                        alias: "alarms_table"
                    }
                },
                static: {
                    value: "static",
                    name: "widget.static",
                    template: {
                        bundleAlias: "cards",
                        alias: "html_card"
                    }
                }
            },
            widgetActionSources: {
                headerButton: {
                    name: 'widget-action.header-button',
                    value: 'headerButton',
                    multiple: true
                }
            },
            widgetActionTypes: {
                openDashboardState: {
                    name: 'widget-action.open-dashboard-state',
                    value: 'openDashboardState'
                },
                updateDashboardState: {
                    name: 'widget-action.update-dashboard-state',
                    value: 'updateDashboardState'
                },
                openDashboard: {
                    name: 'widget-action.open-dashboard',
                    value: 'openDashboard'
                },
                custom: {
                    name: 'widget-action.custom',
                    value: 'custom'
                }
            },
            systemBundleAlias: {
                charts: "charts",
                cards: "cards"
            },
            translate: {
                customTranslationsPrefix: "custom."
            }
        }
    ).name;
