/** @class */
jscape.UserInfo = Class.extend(
    /** @lends {jscape.UserInfo.prototype} */
{
    /** @constructor */
    initialize: function(a, b, c, d, e) {
            this.name = a || "";
            this.login = b || "";
            this.email = c || "";
            this.company = d || "";
            this.owner = e || null;
    }
});
jscape.UserInfo.fromJSON = function(data) {
    return data ? new jscape.UserInfo(data.name, data.login, data.email, data.company, data.owner) : null;
};

/** @class */
jscape.UserData = Class.extend(
    /** @lends {jscape.UserData.prototype} */
{
    /** @constructor */
    initialize: function(name, username, email, company, phone, groups, loginRedirection, expirationTime, owner, enabled, secured, passwordChangingAllowed, adTransferAllowed, usePhoneAuthentication,
                         resources, uploadsQuota, downloadsQuota, transfersQuota, maxTransferRate, maxUploadsPerSession, maxDownloadsPerSession, ipAccessRules) {
        this.name = name;
        this.username = username;
        this.email = email;
        this.company = company;
        this.phone = phone;
        this.groups = groups || [];
        this.loginRedirection = loginRedirection;
        this.expirationTime = parseInt(expirationTime) || null;
        this.owner = owner;
        this.enabled = !!enabled;
        this.secured = !!secured;
        this.passwordChangingAllowed = !!passwordChangingAllowed;
        this.emailFileTransferAllowed = !!adTransferAllowed;
        this.usePhoneAuthentication = !!usePhoneAuthentication;
        this.resources = resources || [];
        this.uploadsQuota = uploadsQuota || null;
        this.downloadsQuota = downloadsQuota || null;
        this.transfersQuota = transfersQuota || null;
        this.maxTransferRate = parseInt(maxTransferRate) || null;
        this.maxUploadsPerSession = parseInt(maxUploadsPerSession) || null;
        this.maxDownloadsPerSession = parseInt(maxDownloadsPerSession) || null;
        this.ipAccessRules = ipAccessRules || [];
    }
});
jscape.UserData.fromJSON = function(data) {
    return data
           ? new jscape.UserData(data.name, data.username, data.email, data.company, jscape.Phone.fromJSON(data.phone), data.groups, data.loginRedirection,
                                 data.expirationTime, data.owner, data.enabled, data.secured, data.passwordChangingAllowed, data.emailFileTransferAllowed, data.usePhoneAuthentication,
                                 $.map(data.resources || [], jscape.VirtualFileData.fromJSON),
                                 jscape.QuotaData.fromJSON(data.uploadsQuota), jscape.QuotaData.fromJSON(data.downloadsQuota), jscape.QuotaData.fromJSON(data.transfersQuota),
                                 data.maxTransferRate, data.maxUploadsPerSession, data.maxDownloadsPerSession, $.map(data.ipAccessRules || [], jscape.IpAccessRule.fromJSON))
            : null;
};

/** @class */
jscape.QuotaData = Class.extend(
    /** @lends {jscape.QuotaData.prototype} */
{
    /** @constructor */
    initialize: function(bytes, resetPeriod) {
        this.bytes = parseInt(bytes) || -1;
        this.resetPeriod = parseInt(resetPeriod) || 0;
    }
});
jscape.QuotaData.fromJSON = function(data) {
    return data ? new jscape.QuotaData(data.bytes, data.resetPeriod) : null;
};

/** @class */
jscape.Phone = Class.extend(
    /** @lends {jscape.Phone.prototype} */
{
    /** @constructor */
    initialize: function(code, number, extension) {
        this.code = code;
        this.number = number;
        this.extension = extension;
    }
});
jscape.Phone.fromJSON = function(data) {
    return data ? new jscape.Phone(data.code, data.number, data.extension) : null;
};

/** @class */
jscape.UserQuotaInfo = Class.extend(
    /** @lends {jscape.UserQuotaInfo.prototype} */
{
    /** @constructor */
    initialize: function(a, b, c) {
        this.uploadsQuota = a || null;
        this.downloadsQuota = b || null;
        this.transfersQuota = c || null;
    }
});
jscape.UserQuotaInfo.fromJSON = function(data) {
    return data ? new jscape.UserQuotaInfo(jscape.QuotaInfo.fromJSON(data.uploadsQuota), jscape.QuotaInfo.fromJSON(data.downloadsQuota), jscape.QuotaInfo.fromJSON(data.transfersQuota)) : null;
};

/** @class */
jscape.DirectoryMonitorInfo = Class.extend(
    /** @lends {jscape.DirectoryMonitorInfo.prototype} */
{
    /** @constructor */
    initialize: function(path, quota) {
        this.path = path || "";
        this.quota = quota || null;
    }
});
jscape.DirectoryMonitorInfo.fromJSON = function(data) {
    return data ? new jscape.DirectoryMonitorInfo(data.path, jscape.QuotaInfo.fromJSON(data.quota)) : null;
};

/** @class */
jscape.QuotaInfo = Class.extend(
    /** @lends {jscape.QuotaInfo.prototype} */
{
    /** @constructor */
    initialize: function(a, b) {
        this.value = parseInt(a) || 0;
        this.currentValue = parseInt(b) || 0;
    },

    exceeded: function () {
        return this.value <= this.currentValue;
    }
});
jscape.QuotaInfo.fromJSON = function(data) {
    return data ? new jscape.QuotaInfo(data.value, data.currentValue) : null;
};

/** @class */
jscape.DropZoneInfo = Class.extend(
    /** @lends {jscape.DropZoneInfo.prototype} */
{
    /** @constructor */
    initialize: function (a, b, c, d, e, f, g, h) {
        this.name = a || "";
        this.account = b || null;
        this.path = c || "";
        this.createDirectoryIfNotExists = !!d;
        this.overwriteFileIfExists = !!e;
        this.theme = f || null;
        this.owner = g || null;
        this.uri = h || "";
    }
});
jscape.DropZoneInfo.fromJSON = function(data) {
    return data ? new jscape.DropZoneInfo(data.name, data.account, data.path, data.createDirectoryIfNotExists, data.overwriteFileIfExists, data.theme, data.owner, data.uri) : null;
};

/** @class */
jscape.KeyPairAlgorithm = Class.extend(
    /** @lends {jscape.KeyPairAlgorithm.prototype} */
{
    /** @constructor */
    initialize: function(name, lengths) {
        this.name = name;
        this.lengths = [].concat(lengths);
    }
});
jscape.KeyPairAlgorithm.RSA = new jscape.KeyPairAlgorithm("RSA", [1024, 2048, 4096]);
jscape.KeyPairAlgorithm.DSA = new jscape.KeyPairAlgorithm("DSA", [1024]);
jscape.KeyPairAlgorithm.values = function() { return [jscape.KeyPairAlgorithm.RSA, jscape.KeyPairAlgorithm.DSA]; };
jscape.KeyPairAlgorithm.lengthsOf = function(algorithm) { return $.map($.grep(jscape.KeyPairAlgorithm.values(), function(item) { return item.name == algorithm; }), function(item) { return item.lengths; }); };
