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



/**
 * 营销列表-潜在客户服务对象基类
 *
 * @export
 * @class ListLeadServiceBase
 * @extends {EntityServie}
 */
export default class ListLeadServiceBase extends EntityService {

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

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

// 实体接口

    /**
     * Select接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListLeadServiceBase
     */
    public async Select(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.contact && context.lead && context.listlead){
            return Http.getInstance().get(`/contacts/${context.contact}/leads/${context.lead}/listleads/${context.listlead}/select`,isloading);
        }
        if(context.campaign && context.lead && context.listlead){
            return Http.getInstance().get(`/campaigns/${context.campaign}/leads/${context.lead}/listleads/${context.listlead}/select`,isloading);
        }
        if(context.ibizlist && context.listlead){
            return Http.getInstance().get(`/ibizlists/${context.ibizlist}/listleads/${context.listlead}/select`,isloading);
        }
        if(context.lead && context.listlead){
            return Http.getInstance().get(`/leads/${context.lead}/listleads/${context.listlead}/select`,isloading);
        }
            return Http.getInstance().get(`/listleads/${context.listlead}/select`,isloading);
    }

    /**
     * CheckKey接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListLeadServiceBase
     */
    public async CheckKey(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.contact && context.lead && context.listlead){
            return Http.getInstance().post(`/contacts/${context.contact}/leads/${context.lead}/listleads/${context.listlead}/checkkey`,data,isloading);
        }
        if(context.campaign && context.lead && context.listlead){
            return Http.getInstance().post(`/campaigns/${context.campaign}/leads/${context.lead}/listleads/${context.listlead}/checkkey`,data,isloading);
        }
        if(context.ibizlist && context.listlead){
            return Http.getInstance().post(`/ibizlists/${context.ibizlist}/listleads/${context.listlead}/checkkey`,data,isloading);
        }
        if(context.lead && context.listlead){
            return Http.getInstance().post(`/leads/${context.lead}/listleads/${context.listlead}/checkkey`,data,isloading);
        }
            return Http.getInstance().post(`/listleads/${context.listlead}/checkkey`,data,isloading);
    }

    /**
     * Remove接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListLeadServiceBase
     */
    public async Remove(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.contact && context.lead && context.listlead){
            return Http.getInstance().delete(`/contacts/${context.contact}/leads/${context.lead}/listleads/${context.listlead}`,isloading);
        }
        if(context.campaign && context.lead && context.listlead){
            return Http.getInstance().delete(`/campaigns/${context.campaign}/leads/${context.lead}/listleads/${context.listlead}`,isloading);
        }
        if(context.ibizlist && context.listlead){
            return Http.getInstance().delete(`/ibizlists/${context.ibizlist}/listleads/${context.listlead}`,isloading);
        }
        if(context.lead && context.listlead){
            return Http.getInstance().delete(`/leads/${context.lead}/listleads/${context.listlead}`,isloading);
        }
            return Http.getInstance().delete(`/listleads/${context.listlead}`,isloading);

    }

    /**
     * Create接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListLeadServiceBase
     */
    public async Create(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.contact && context.lead && true){
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
            return Http.getInstance().post(`/contacts/${context.contact}/leads/${context.lead}/listleads`,data,isloading);
        }
        if(context.campaign && context.lead && true){
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
            return Http.getInstance().post(`/campaigns/${context.campaign}/leads/${context.lead}/listleads`,data,isloading);
        }
        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}/listleads`,data,isloading);
        }
        if(context.lead && true){
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
            return Http.getInstance().post(`/leads/${context.lead}/listleads`,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(`/listleads`,data,isloading);
        return res;
    }

    /**
     * Update接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListLeadServiceBase
     */
    public async Update(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.contact && context.lead && context.listlead){
            return Http.getInstance().put(`/contacts/${context.contact}/leads/${context.lead}/listleads/${context.listlead}`,data,isloading);
        }
        if(context.campaign && context.lead && context.listlead){
            return Http.getInstance().put(`/campaigns/${context.campaign}/leads/${context.lead}/listleads/${context.listlead}`,data,isloading);
        }
        if(context.ibizlist && context.listlead){
            return Http.getInstance().put(`/ibizlists/${context.ibizlist}/listleads/${context.listlead}`,data,isloading);
        }
        if(context.lead && context.listlead){
            return Http.getInstance().put(`/leads/${context.lead}/listleads/${context.listlead}`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().put(`/listleads/${context.listlead}`,data,isloading);
            return res;
    }

    /**
     * Save接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListLeadServiceBase
     */
    public async Save(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.contact && context.lead && context.listlead){
            return Http.getInstance().post(`/contacts/${context.contact}/leads/${context.lead}/listleads/${context.listlead}/save`,data,isloading);
        }
        if(context.campaign && context.lead && context.listlead){
            return Http.getInstance().post(`/campaigns/${context.campaign}/leads/${context.lead}/listleads/${context.listlead}/save`,data,isloading);
        }
        if(context.ibizlist && context.listlead){
            return Http.getInstance().post(`/ibizlists/${context.ibizlist}/listleads/${context.listlead}/save`,data,isloading);
        }
        if(context.lead && context.listlead){
            return Http.getInstance().post(`/leads/${context.lead}/listleads/${context.listlead}/save`,data,isloading);
        }
        let masterData:any = {};
        Object.assign(data,masterData);
            let res:any = await  Http.getInstance().post(`/listleads/${context.listlead}/save`,data,isloading);
            return res;
    }

    /**
     * Get接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListLeadServiceBase
     */
    public async Get(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.contact && context.lead && context.listlead){
            return Http.getInstance().get(`/contacts/${context.contact}/leads/${context.lead}/listleads/${context.listlead}`,isloading);
        }
        if(context.campaign && context.lead && context.listlead){
            return Http.getInstance().get(`/campaigns/${context.campaign}/leads/${context.lead}/listleads/${context.listlead}`,isloading);
        }
        if(context.ibizlist && context.listlead){
            return Http.getInstance().get(`/ibizlists/${context.ibizlist}/listleads/${context.listlead}`,isloading);
        }
        if(context.lead && context.listlead){
            return Http.getInstance().get(`/leads/${context.lead}/listleads/${context.listlead}`,isloading);
        }
            let res:any = await Http.getInstance().get(`/listleads/${context.listlead}`,isloading);
            return res;

    }

    /**
     * GetDraft接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ListLeadServiceBase
     */
    public async GetDraft(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        if(context.contact && context.lead && true){
            return Http.getInstance().get(`/contacts/${context.contact}/leads/${context.lead}/listleads/getdraft`,isloading);
        }
        if(context.campaign && context.lead && true){
            return Http.getInstance().get(`/campaigns/${context.campaign}/leads/${context.lead}/listleads/getdraft`,isloading);
        }
        if(context.ibizlist && true){
            return Http.getInstance().get(`/ibizlists/${context.ibizlist}/listleads/getdraft`,isloading);
        }
        if(context.lead && true){
            return Http.getInstance().get(`/leads/${context.lead}/listleads/getdraft`,isloading);
        }
        let res:any = await  Http.getInstance().get(`/listleads/getdraft`,isloading);
        res.data.listlead = data.listlead;
        return res;
    }

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