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



/**
 * 营销列表-账户服务对象基类
 *
 * @export
 * @class ListAccountServiceBase
 * @extends {EntityServie}
 */
export default class ListAccountServiceBase extends EntityService {

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

    /**
     * 初始化基础数据
     *
     * @memberof ListAccountServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='listaccount';
        this.APPDEKEY = 'relationshipsid';
        this.APPDENAME = 'listaccounts';
        this.APPDETEXT = 'relationshipsname';
        this.APPNAME = 'businesscentral';
        this.SYSTEMNAME = 'ibizbusinesscentral';
    }

// 实体接口

    /**
     * Select接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListAccountServiceBase
     */
    public async Select(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.ibizlist && context.listaccount){
            return Http.getInstance().get(`/ibizlists/${context.ibizlist}/listaccounts/${context.listaccount}/select`,isloading);
        }
        if(context.account && context.listaccount){
            return Http.getInstance().get(`/accounts/${context.account}/listaccounts/${context.listaccount}/select`,isloading);
        }
            return Http.getInstance().get(`/listaccounts/${context.listaccount}/select`,isloading);
    }

    /**
     * CheckKey接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListAccountServiceBase
     */
    public async CheckKey(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.ibizlist && context.listaccount){
            return Http.getInstance().post(`/ibizlists/${context.ibizlist}/listaccounts/${context.listaccount}/checkkey`,data,isloading);
        }
        if(context.account && context.listaccount){
            return Http.getInstance().post(`/accounts/${context.account}/listaccounts/${context.listaccount}/checkkey`,data,isloading);
        }
            return Http.getInstance().post(`/listaccounts/${context.listaccount}/checkkey`,data,isloading);
    }

    /**
     * Remove接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListAccountServiceBase
     */
    public async Remove(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.ibizlist && context.listaccount){
            return Http.getInstance().delete(`/ibizlists/${context.ibizlist}/listaccounts/${context.listaccount}`,isloading);
        }
        if(context.account && context.listaccount){
            return Http.getInstance().delete(`/accounts/${context.account}/listaccounts/${context.listaccount}`,isloading);
        }
            return Http.getInstance().delete(`/listaccounts/${context.listaccount}`,isloading);

    }

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

    /**
     * GetDraft接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListAccountServiceBase
     */
    public async GetDraft(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.ibizlist && true){
            return Http.getInstance().get(`/ibizlists/${context.ibizlist}/listaccounts/getdraft`,isloading);
        }
        if(context.account && true){
            return Http.getInstance().get(`/accounts/${context.account}/listaccounts/getdraft`,isloading);
        }
        let res:any = await  Http.getInstance().get(`/listaccounts/getdraft`,isloading);
        res.data.listaccount = data.listaccount;
        return res;
    }

    /**
     * Update接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListAccountServiceBase
     */
    public async Update(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.ibizlist && context.listaccount){
            return Http.getInstance().put(`/ibizlists/${context.ibizlist}/listaccounts/${context.listaccount}`,data,isloading);
        }
        if(context.account && context.listaccount){
            return Http.getInstance().put(`/accounts/${context.account}/listaccounts/${context.listaccount}`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().put(`/listaccounts/${context.listaccount}`,data,isloading);
            return res;
    }

    /**
     * Get接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListAccountServiceBase
     */
    public async Get(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.ibizlist && context.listaccount){
            return Http.getInstance().get(`/ibizlists/${context.ibizlist}/listaccounts/${context.listaccount}`,isloading);
        }
        if(context.account && context.listaccount){
            return Http.getInstance().get(`/accounts/${context.account}/listaccounts/${context.listaccount}`,isloading);
        }
            let res:any = await Http.getInstance().get(`/listaccounts/${context.listaccount}`,isloading);
            return res;

    }

    /**
     * Create接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListAccountServiceBase
     */
    public async Create(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.ibizlist && true){
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
            return Http.getInstance().post(`/ibizlists/${context.ibizlist}/listaccounts`,data,isloading);
        }
        if(context.account && true){
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
            return Http.getInstance().post(`/accounts/${context.account}/listaccounts`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
        if(!data.srffrontuf || data.srffrontuf !== "1"){
            data[this.APPDEKEY] = null;
        }
        if(data.srffrontuf){
            delete data.srffrontuf;
        }
        let tempContext:any = JSON.parse(JSON.stringify(context));
        let res:any = await Http.getInstance().post(`/listaccounts`,data,isloading);
        return res;
    }

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