import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {CommonsService} from './commons.service';
import {environment} from '../../environments/environment';

@Injectable({
    providedIn: 'root'
})
export class AgentService {


    constructor(
        private http: HttpClient,
        private common: CommonsService
    ) {
    }

    /**
     * 查询列表
     *
     * @param  paramsObject   对象
     * @param  callBack   回调
     */
    public getListAgent(paramsObject: object, callBack) {
        this.http.get(environment.baseUrl + 'highAgent/getListAgent?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 新增
     *
     * @param params 上传对象
     * @param  callBack   回调
     * @return data 返回结果
     */
    public insertAgent(params: object, callBack) {
        this.http.post(environment.baseUrl + 'highAgent/insertAgent', params).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 修改卡券
     *
     * @param params 上传对象
     * @param  callBack   回调
     * @return data 返回结果
     */
    public updateAgent(params: object, callBack) {
        this.http.post(environment.baseUrl + 'highAgent/updateAgent', params).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 根据id查询详情
     *
     * @param  agentId   id
     * @param  callBack   回调
     */
    public findByAgentId(agentId: number, callBack) {
        this.http.get(environment.baseUrl + 'highAgent/findByAgentId?agentId=' + agentId).subscribe(data => {
            callBack(data);
        });
    }


    /**
     * 修改公司状态
     *
     * @param id  用户id
     * @param status  status
     * @param callBack 返回参数
     */
    public editStatus(id: number, callBack) {
        this.http.get(environment.baseUrl + 'highAgent/forbiddenUser?agentId=' + id).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 生成二维码
     *
     * @param id  用户id
     * @param status  status
     * @param callBack 返回参数
     */
    public generateRechargeAgentQrCode(id: number, callBack) {
        this.http.get(environment.baseUrl + 'highAgent/generateRechargeAgentQrCode?agentId=' + id).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 分配优惠券给代理商
     *
     * @param params 上传对象
     * @param  callBack   回调
     * @return data 返回结果
     */
    public insertDiscountAgent(params: object, callBack) {
        this.http.post(environment.baseUrl + 'discountAgentRel/insertDiscountAgent', params).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 分配卡券给代理商
     *
     * @param params 上传对象
     * @param  callBack   回调
     * @return data 返回结果
     */
    public assignCouponAgent(params: object, callBack) {
        this.http.post(environment.baseUrl + 'highCouponAgent/assignCouponAgent', params).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 查询列表
     *
     * @param  paramsObject   对象
     * @param  callBack   回调
     */
    public getDiscountAgentList(paramsObject: object, callBack) {
        this.http.get(environment.baseUrl + 'discountAgentRel/getDiscountAgentList?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 查询列表
     *
     * @param  paramsObject   对象
     * @param  callBack   回调
     */
    public getCouponByAgent(paramsObject: object, callBack) {
        this.http.get(environment.baseUrl + 'highCouponAgent/getCouponByAgent?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 查询优惠券码列表
     *
     * @param  paramsObject   对象
     * @param  callBack   回调
     */
    public getDiscountCodeList(paramsObject: object, callBack) {
        this.http.get(environment.baseUrl + 'discountAgentRel/getDiscountCodeList?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 根据卡券与代理商关系 查询分发记录
     *
     * @param  paramsObject   对象
     * @param  callBack   回调
     */
    public getRecordByCouponAgentId(paramsObject: object, callBack) {
        this.http.get(environment.baseUrl + 'highCouponAgent/getRecordByCouponAgentId?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
            callBack(data);
        });
    }


    /**
     * 代理商统计
     *
     * @param  type   类型
     * @param  callBack   回调
     */
    public getAgentCount(type , callBack) {
        console.log(type);
        this.http.get(environment.baseUrl + 'highCouponAgent/getAgentCount?type=' + type).subscribe(data => {
            callBack(data);
        });
    }

    public getDiscountStatus(params: object, callBack) {
        this.http.post(environment.baseUrl + 'discountAgentRel/getDiscountStatus', params).subscribe(data => {
            callBack(data);
        });
    }

    public getReceiveLink(id: number, callBack) {
        this.http.get(environment.baseUrl + 'discountAgentRel/getReceiveLink?id=' + id).subscribe(data => {
            callBack(data);
        });
    }
}
