import { Http,Util } from '@/utils';
import EntityService from '../entity-service';



/**
 * 登录账号服务对象基类
 *
 * @export
 * @class LoginAccountServiceBase
 * @extends {EntityServie}
 */
export default class LoginAccountServiceBase extends EntityService {

    /**
     * Creates an instance of  LoginAccountServiceBase.
     * 
     * @param {*} [opts={}]
     * @memberof  LoginAccountServiceBase
     */
    constructor(opts: any = {}) {
        super(opts);
    }

    /**
     * 初始化基础数据
     *
     * @memberof LoginAccountServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='loginaccount';
        this.APPDEKEY = 'loginaccountid';
        this.APPDENAME = 'loginaccounts';
        this.APPDETEXT = 'loginaccountname';
    }

// 实体接口

    /**
     * Get接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async Get(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && context.loginaccount){
            return Http.getInstance().get(`/users/${context.user}/loginaccounts/${context.loginaccount}`,isloading);
        }
            let res:any = await Http.getInstance().get(`/loginaccounts/${context.loginaccount}`,isloading);
            return res;

    }

    /**
     * CheckKey接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async CheckKey(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && context.loginaccount){
            return Http.getInstance().post(`/users/${context.user}/loginaccounts/${context.loginaccount}/checkkey`,data,isloading);
        }
            return Http.getInstance().post(`/loginaccounts/${context.loginaccount}/checkkey`,data,isloading);
    }

    /**
     * UpdatePWD接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async UpdatePWD(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && context.loginaccount){
            return Http.getInstance().put(`/users/${context.user}/loginaccounts/${context.loginaccount}/updatepwd`,data,isloading);
        }
            return Http.getInstance().put(`/loginaccounts/${context.loginaccount}/updatepwd`,data,isloading);
    }

    /**
     * Save接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async Save(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && context.loginaccount){
            return Http.getInstance().post(`/users/${context.user}/loginaccounts/${context.loginaccount}/save`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().post(`/loginaccounts/${context.loginaccount}/save`,data,isloading);
            return res;
    }

    /**
     * Remove接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async Remove(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && context.loginaccount){
            return Http.getInstance().delete(`/users/${context.user}/loginaccounts/${context.loginaccount}`,isloading);
        }
            return Http.getInstance().delete(`/loginaccounts/${context.loginaccount}`,isloading);

    }

    /**
     * Create接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async Create(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && true){
            data[this.APPDEKEY] = null;
            return Http.getInstance().post(`/users/${context.user}/loginaccounts`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
        data[this.APPDEKEY] = null;
        let tempContext:any = JSON.parse(JSON.stringify(context));
        let res:any = await Http.getInstance().post(`/loginaccounts`,data,isloading);
        return res;
    }

    /**
     * GetDraft接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async GetDraft(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && true){
            return Http.getInstance().get(`/users/${context.user}/loginaccounts/getdraft`,isloading);
        }
        let res:any = await  Http.getInstance().get(`/loginaccounts/getdraft`,isloading);
        res.data.loginaccount = data.loginaccount;
        return res;
    }

    /**
     * Update接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async Update(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && context.loginaccount){
            return Http.getInstance().put(`/users/${context.user}/loginaccounts/${context.loginaccount}`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().put(`/loginaccounts/${context.loginaccount}`,data,isloading);
            return res;
    }

    /**
     * FetchGetLoginaccount接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async FetchGetLoginaccount(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/users/${context.user}/loginaccounts/fetchgetloginaccount`,tempData,isloading);
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        return Http.getInstance().get(`/loginaccounts/fetchgetloginaccount`,tempData,isloading);
    }

    /**
     * FetchDefault接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof LoginAccountServiceBase
     */
    public async FetchDefault(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.user && true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().get(`/users/${context.user}/loginaccounts/fetchdefault`,tempData,isloading);
        }
        let tempData:any = JSON.parse(JSON.stringify(data));
        return Http.getInstance().get(`/loginaccounts/fetchdefault`,tempData,isloading);
    }
}