﻿(function () {
    var svc = function ($q) {
        var self = this;
        var defaultCheck = function(){ return true; }
        var defer;
        var numberCheck = defaultCheck;
        self.numbers = [];

        self.showPick = function (numberArray, numCheckFunc) {
            if (numberArray instanceof Array) {
                numberCheck = typeof numCheckFunc === "function" ? numCheckFunc : defaultCheck;
                defer = $q.defer();
                self.numbers = numberArray;
                return defer.promise;
            }
            return $q.reject();
        }

        self.handlePick = function (num) {
            if (self.numbers.indexOf(num) >= 0 && numberCheck(num) && defer) {
                defer.resolve(num);
                numConfig = null;
                defer = null;
            }
        }
    }
    angular.module("lottery.services").service("numberSelectionSvc", ["$q", svc]);
})();