/// <reference path="./sigApi.ApiBase.d.ts" />
/// <reference path="./sigApi.PermissionResolveObj.d.ts" />
/// <reference path="./sigApi.Role.d.ts" />
/// <reference path="./sigApi.RoleObj.d.ts" />
/// <reference path="./sigApi.User.d.ts" />
/// <reference path="./sigApi.UserObj.d.ts" />

declare namespace SigApi {
    interface ApiUserManager extends ApiBase {
        /**
         * Can be used by the usermanagement controls for communication
         * 
         * @type {Map} 
         */
        readonly keyValueStore: Map<any, any>
        /**
         * Returns a array with user objects for all, only active or only inactive user accounts
         *
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @param {number} [usersState]  0: all user, 1: only active users, 2: only inactive users
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {User[]} users }) => void, reject: ({  {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with an Array of Users
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        getUserList(
            uid?: number,
            usersState?: number
        ): Promise<{ uid: number, users: User[] }>
        /**
         * Returns the user object of a specific user account
         *
         * @param {number|string|UserObj} user user id, username, user object user-identifier
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {User} user}) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the corresponding User
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        getUser(
            user: number | string | UserObj,
            uid?: number
        ): Promise<{ uid: number, user: User | null }>
        /**
         * Returns the user object of a specific user account
         *
         * @param {number|string|UserObj} user user id, username, user object user-identifier
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {User} user }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the corresponding User
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        getUserDetail(
            user: number | string | UserObj,
            uid?: number
        ): Promise<{ uid: number, user: User | null }>
        /**
         * Creates new user account(s) and publish the event USER_CREATED
         *
         * @param {UserObj|UserObj[]} user an array or a single instance of valid user object(s)
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {UserObj|UserObj[]} data }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid and the passed data in the data attribute
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        createUser(
            user: UserObj | UserObj[],
            source?: string,
            target?: string[],
            data?: object,
            uid?: number
        ): Promise<{ uid: number, data: UserObj | UserObj[] }>
        /**
         * Updates existing user account(s) and publish the event USER_UPDATED
         *
         * @param {UserObj|UserObj[]} user an array or a single instance of valid user object(s)
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {UserObj|UserObj[]} data } }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        updateUser(
            user: UserObj | UserObj[],
            source?: string,
            target?: string[],
            data?: object,
            uid?: number
        ): Promise<{ uid: number, data: UserObj | UserObj[] }>
        /**
         * Changes the user's password
         *
         * @param {string} oldPW old password
         * @param {string} newPW new password
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        changeUserPW(
            oldPW: string,
            newPW: string,
            uid?: number
        ): Promise<{ uid: number }>
        /**
         * Delete existing user account(s) and publish the event USER_DELETED
         *
         * @param {number|string|UserObj|(number|string|UserObj)[]} userName user id, username, user object user-identifier or an array of user-identifiers
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * @param {boolean} [forced=false]  if true, the user is permanently deleted, otherwise only deactivated
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        deleteUser(
            userName: number | string | UserObj | (number | string | UserObj)[],
            source?: string,
            target?: string[],
            data?: object,
            uid?: number,
            forced?: boolean
        ): Promise<{ uid: number }>
        /**
         * Restore deleted user account(s) and publish the event USER_RESTORED
         *
         * @param {number|string|UserObj|(number|string|UserObj)[]} userName user id, username, user object user-identifier or an array of user-identifiers
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        restoreUser(
            userName: number | string | UserObj | (number | string | UserObj)[],
            source?: string,
            target?: string[],
            data?: object,
            uid?: number
        ): Promise<{ uid: number }>
        /**
         * Permanently remove deleted user accounts
         * 
         * @param {number} [uid=undefined] a unique identifier
         * @returns {Promise} Promise -> resolve: ({ {number} uid }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         */
        cleanUpUsers(uid?: number): Promise<{ uid: number }>
        /**
         * Returns the user object of the currently logged in user account
         *
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {User} user }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the currently logged in user
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        getActiveUser(uid?: number): Promise<{ uid: number, user: User | null }>
        /**
         * Returns a array with user objects for all user accounts belonging to a specific role
         *
         * @param {string|number|RoleObj} role role id, role name, role object role-identifier
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {User[]} users }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with all Users which belongs to the specified role
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        getUsersByRole(role: number | string | RoleObj, uid?: number): Promise<{ uid: number, users: User[] }>
        /**
         * Get the permission object for a specific user
         *
         * @param {number|string|UserObj} user user id, username, user object user-identifier
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise<PermissionResolveObj|PermissionRejectObj>} 
         */
        getUserPermissions(
            user: number | string | UserObj,
            uid?: number
        ): Promise<PermissionResolveObj>
        /**
         * Checks if a user is granted a specific permission
         *
         * @param {string} [permission=''] a valid PERMISSION_NAME constant from the SIG_CONST API
         * @param {string} user a valid user name, if undefined fallback to active user
         * 
         * @returns {Promise} returns a Promise, which is resolved with true if the user is granted the permission or false if not
         */
        hasPermission(permission?: string, user?: string): Promise<boolean>
        /**
         * Returns a object of all system permissions and their default values
         *
         * @param {number} [uid=undefined]
         * 
         * @returns {Promise<PermissionResolveObj|PermissionRejectObj>}
         */
        getDefaultPermissions(uid?: number): Promise<PermissionResolveObj>
        /**
         * Returns a array with role objects for all defined roles
         *
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {Role[]} roles }) => void, reject: ({ {number} uid, {number} status, {string} errortxt}) => void
         * 
         * Returns a Promise, which is resolved with an Array of Roles
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        getRoleList(uid?: number): Promise<{ uid: number, roles: Role[] }>
        /**
         * Returns the role object of a specific role name
         *
         * @param {number|string|RoleObj} role role id, role name, role object role-identifier
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {Role} role }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the coresponding role
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        getRole(role: number | string | RoleObj, uid?: number): Promise<{ uid: number, role: Role | null }>
        /**
         * Returns the role object of a specific role name
         *
         * @param {number|string|RoleObj} role role id, role name, role object role-identifier
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {Role} role }) => void, reject: ({ {number} uid, {number} status, {string} errortxt}) => void
         * 
         * Returns a Promise, which is resolved with the coresponding role
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        getRoleDetail(
            role: number | string | RoleObj,
            uid?: number
        ): Promise<{ uid: number, role: Role | null }>
        /**
         * Creates new role(s) and publish the event ROLE_CREATED
         *
         * @param {RoleObj|RoleObj[]} role an array or a single instance of valid role object(s)
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {RoleObj|RoleObj[]} data }) => void, reject: ({ {number} uid, {number} status, {string} errortxt}) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        createRole(
            role: RoleObj | RoleObj[],
            source?: string,
            target?: string[],
            data?: object,
            uid?: number
        ): Promise<{ uid: number, data: RoleObj | RoleObj[] }>
        /**
         * Updates existing role(s) and publish the event ROLE_UPDATED
         *
         * @param {RoleObj|RoleObj[]} role an array or a single instance of valid role object(s)
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid, {RoleObj|RoleObj[]} data }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        updateRole(
            role: RoleObj | RoleObj[],
            source?: string,
            target?: string[],
            data?: object,
            uid?: number
        ): Promise<{ uid: number, data: RoleObj | RoleObj[] }>
        /**
         * Delete existing role(s) and publish the event ROLE_DELETED
         *
         * @param {number|string|RoleObj|(number|string|RoleObj)[]} role role id, role name, role object role-identifier or an array of role-identifiers
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * @param {boolean} [forced=false]  if true, the deletion of the roles is forced
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        deleteRole(
            role: number | string | RoleObj | (number | string | RoleObj)[],
            source?: string,
            target?: string[],
            data?: object,
            uid?: number,
            forced?: boolean
        ): Promise<{ uid: number }>
        /**
         * Delete existing role(s), whether they are used or not, and publish the event ROLE_DELETED
         *
         * @param {number|string|RoleObj|(number|string|RoleObj)[]} role role id, role name, role object role-identifier or an array of role-identifiers
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        deleteRoleForced(role: number | string | RoleObj | (number | string | RoleObj)[]): Promise<{ uid: number }>
        /**
         * Login a existing user account and publish the event USER_LOGGED_IN
         *
         * @param {string} userName
         * @param {string} password
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        login(
            userName: string,
            password: string,
            source?: string,
            target?: string[],
            data?: object,
            uid?: number
        ): Promise<{ uid: number }>
        /**
         * Logout the currently logged in user account and publish the event USER_LOGGED_OUT
         * 
         * @param {string} [source=null] a string with the instanceId of the source component, which is passed to the emitted system event
         * @param {string[]} [target=null] null or an array with the instanceIds of the target components, which is passed to the emitted system event
         * @param {object} [data=null] a object which is passed to the emitted system event
         * @param {number} [uid=undefined]  a unique identifier
         * 
         * @returns {Promise} Promise -> resolve: ({ {number} uid }) => void, reject: ({ {number} uid, {number} status, {string} errortxt }) => void
         * 
         * Returns a Promise, which is resolved with the uid
         * 
         * If the promise is rejected, an object with uid, status and errortxt is passed in the reject function
         */
        logout(
            source?: string,
            target?: string[],
            data?: object,
            uid?: number
        ): Promise<{ uid: number }>
        /**
         * export users
         * 
         * @param {string[]} userNames 
         * @param {boolean} [dryrun=false] 
         * @param {number} [uid=undefined] a unique identifier
         * @returns {Promise} resolve({string}), reject({ {number} status, {string} errortxt, {object[]} userResults })
         *                    {object} userResult: { {string} userName, {number} status, {string} errortxt }
         */
        exportUser(userNames: string[], dryrun?: boolean, uid?: number): Promise<string>
        /**
         * import users
         * 
         * @param {string} importString 
         * @param {boolean} [overwrite=false] 
         * @param {boolean} [dryrun=false] 
         * @param {number} [uid=undefined] a unique identifier
         * @returns {Promise} resolve(), reject({ {number} status, {string} errortxt, {object[]} userResults })
         *                    {object} userResult: { {string} userName, {number} status, {string} errortxt }
         */
        importUser(importString: string, overwrite?: boolean, dryrun?: boolean, uid?: number): Promise<void>
        /**
         * export roles
         * 
         * @param {string[]} roleNames 
         * @param {boolean} [dryrun=false] 
         * @param {number} [uid=undefined] a unique identifier
         * @returns {Promise} resolve({string}), reject({ {number} status, {string} errortxt, {object[]} roleResults })
         *                    {object} roleResult: { {string} roleName, {number} status, {string} errortxt }
         */
        exportRole(roleNames: string[], dryrun?: boolean, uid?: number): Promise<string>
        /**
         * import roles
         * 
         * @param {string} importString 
         * @param {boolean} [overwrite=false] 
         * @param {boolean} [dryrun=false] 
         * @param {number} [uid=undefined] a unique identifier
         * @returns {Promise} resolve(), reject({ {number} status, {string} errortxt, {object[]} roleResults })
         *                    {object} roleResult: { {string} roleName, {number} status, {string} errortxt }
         */
        importRole(importString: string, overwrite?: boolean, dryrun?: boolean, uid?: number): Promise<void>
        /**
         * Checks if the password is valid
         *
         * @param {string} password
         * 
         * @returns {boolean} true if the password is valid or false if not
         */
        isValidPassword(password: string): boolean
        /**
         * Checks if the username is valid
         *
         * @param {string} userName
         * 
         * @returns {boolean} true if the username is valid or false if not
         */
        isValidUsername(userName: string): boolean
        /**
         * Checks if the rolename is valid
         *
         * @param {string} roleName
         * 
         * @returns {boolean} true if the rolename is valid or false if not
         */
        isValidRolename(roleName: string): boolean
        /**
         * Checks if the access string of a role is valid
         *
         * @param {string} accessString
         * 
         * @returns {boolean} true if the access string is valid or false if not
         */
        isValidAccessString(accessString: string): boolean
        /**
         * Checks if a user is logged in
         *
         * @returns {boolean}  true if the user is logged in or false if not
         */
        isUserLoggedIn(): boolean,
        /**
         * Function to check if parameter object is a instanceof User.
         * This function can be used without importing the type User to be used with the instanceof operator.
         * @param {*} object Any object to type check
         * @returns {boolean} Returns true if parameter object is instanceof User, else false
         */
        instanceofUser(object: any): boolean
        /**
         * Function to check if parameter object is a instanceof Role.
         * This function can be used without importing the type Role to be used with the instanceof operator.
         * @param {*} object Any object to type check
         * @returns {boolean} Returns true if parameter object is instanceof Role, else false
         */
        instanceofRole(object: any): boolean
    }
}
