(function (paw, utils) {
    function InventoryFixedAssetsIdentService() {
        this.settings = {
            identApiUrl: undefined,
            identRemovePositionApiUrl: undefined,
            itemsSearchApiUrl: undefined,
            addFixedAssetApiUrl: undefined,
            locationSearchApiUrl: undefined
        };
    }

    InventoryFixedAssetsIdentService.prototype.setup = function (settings) {
        paw.lang.append(settings, this.settings);
    };

    InventoryFixedAssetsIdentService.prototype.fetchIdents = function (id) {
        if (utils.value.notSet(this.settings.identApiUrl)) {
            console.error("Inventory Fixed assets ident service fetch idents: API url not set!");
            return utils.async.reject();
        }
        var d = utils.async.defer();
        $.ajax({
            url: this.settings.identApiUrl + '?id=' + id,
            success: function (idents) {
                d.resolve(idents);
            },
            error: function () {
                d.reject();
            }
        });
        return d.promise;
    }; 

    InventoryFixedAssetsIdentService.prototype.removeIdentPosition = function (ident) {
        if (utils.value.notSet(this.settings.identRemovePositionApiUrl)) {
            console.error("Inventory Fixed assets ident service remove ident position: API url not set!");
            return utils.async.reject();
        }
        var d = utils.async.defer();
        $.ajax({
            url: this.settings.identRemovePositionApiUrl,
            type: 'POST',
            data: {
                AcKey: ident.AcKey,
                AnNo: ident.AnNo
            },
            success: function () {
                d.resolve();
            },
            error: function () {
                d.reject();
            }
        });
        return d.promise;
    };

    InventoryFixedAssetsIdentService.prototype.findItems = function (searchTerm) {
        var d = utils.async.defer();
        $.ajax({
            type: 'post',
            url: this.settings.itemsSearchApiUrl,
            data: {
                Keywords: searchTerm,
                Length: 100,
                Start: 0
            },
            success: function (response) {
                d.resolve(response);
            },
            error: function () {
                d.reject();
            }
        });
        return d.promise;
    };

    InventoryFixedAssetsIdentService.prototype.addFixedAsset = function (fa) {
        var d = utils.async.defer();
        $.ajax({
            type: 'post',
            url: this.settings.addFixedAssetApiUrl,
            data: fa,
            success: function (response) {
                d.resolve(response);
            },
            error: function () {
                d.reject();
            }
        });
        return d.promise;
    };

    paw.view.inventoryFixedAssets.inventoryFixedAssetsIdentService = new InventoryFixedAssetsIdentService();
})(paw, paw.utils);