'use strict';

var ClassificationFactory = angular.module('classifications.factory', [
]).factory('ClassificationFactory', [
    'Common',
    function(Common) {

        function Classification(data) {
            var self = this;
            // merge data
            if (data) angular.extend(this, data);
            // extend members
            //this.IsFlat = this.ClassificationType.Value == 0;
            //this.IsHierarchy = this.ClassificationType.Value == 1;
            
        }

        function EditClassification(data) {
            var self = this;
            // merge data
            if (data) angular.extend(this, data);
        }

        var create = function(data) {
            return new Classification(data);
        };

        var edit = function(data) {
            return new EditClassification(data);
        };

        return {
            create: create,
            edit: edit
        };
    }
])
    .factory('LabelFactory', [
        'Common',
        function (Common) {
            
            var expanded = [];
            
            function Label(data) {
                var self = this;
                // merge data
                if (data) angular.extend(this, data);
                // extend members
            }

            var create = function(data) {
                return new Label(data);
            };
            
            var addExpanded = function (id) {
                var exist = false;

                for (var i = 0; i < expanded.length; i++) {
                    if (expanded[i] === id) {
                        exist = true;
                    }
                }

                if (exist == false) {
                    expanded.push(id);
                }
            };

            var removeExpanded = function (id) {
                angular.forEach(expanded, function (value, key) {
                    if (value == id) {
                        expanded.splice(key, 1);
                    }
                });
            };

            var allExpanded = function () {
                return expanded;
            };

            return {
                create: create,
                addExpanded: addExpanded,
                allExpanded: allExpanded,
                removeExpanded: removeExpanded
            };
        }
    ]);