import UserRoleTypeService from '@service/user-role-type/user-role-type-service';
/**
 * 代码表--用户角色类型
 *
 * @export
 * @class UserRoleType
 */
export default class UserRoleType { 

    /**
     * 用户角色类型应用实体服务对象
     *
     * @type {UserRoleTypeService}
     * @memberof UserRoleType
     */
    public userroletypeService: UserRoleTypeService = new UserRoleTypeService();


    /**
     * 处理数据
     *
     * @private
     * @param {any[]} items
     * @returns {any[]}
     * @memberof UserRoleType
     */
    private doItems(items: any[]): any[] {
        let _items: any[] = [];
        items.forEach((item: any) => {
            let itemdata:any = {};
            Object.assign(itemdata,{id:item.userroletypeid});
            Object.assign(itemdata,{value:item.userroletypeid});
            Object.assign(itemdata,{text:item.userroletypename});
            _items.push(itemdata);
        });
        return _items;
    }

    /**
     * 获取数据项
     *
     * @param {*} context
     * @param {*} data
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof UserRoleType
     */
    public getItems(context: any={}, data: any={}, isloading?: boolean): Promise<any> {
        return new Promise((resolve, reject) => {
            const promise: Promise<any> = this.userroletypeService.FetchDefault(context, data, isloading);
            promise.then((response: any) => {
                if (response && response.status === 200) {
                    const data =  response.data;
                    resolve(this.doItems(data));
                } else {
                    reject([])
                }
            }).catch((response: any) => {
                reject([])
            });
        });
    }
}
