# -*- coding: utf-8 -*-
from .type import RequestType


class GoldPlan:
    """
    经营能力——点金计划
    参考 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_5_1.shtml
    仅支持服务商
    """

    def __init__(self, parent):
        from .mch import WeChatPay

        if not isinstance(parent, WeChatPay):
            raise Exception('BasePay need WeChatPay!')
        self._p = parent    # 父对象， 服务商

    def plan_change(self, sub_mchid, operation_type):
        """点金计划管理
        :param sub_mchid: 子商户的商户号，由微信支付生成并下发。示例值:'1900000109'
        :param operation_type: 操作类型, 枚举值:'OPEN':表示开通点金计划，'CLOSE':表示关闭点金计划。示例值:'OPEN'
        """
        params = {}
        if sub_mchid:
            params.update({'sub_mchid': sub_mchid})
        else:
            raise Exception('sub_mchid is not assigned.')
        if operation_type:
            params.update({'operation_type': operation_type})
        else:
            raise Exception('operation_type is not assigned.')
        path = 'https://api.mch.weixin.qq.com/v3/goldplan/merchants/changegoldplanstatus'
        return self._p.core.request(path, method=RequestType.POST, data=params)

    def custom_page_change(self, sub_mchid, operation_type):
        """商家小票管理
        :param sub_mchid: 子商户的商户号，由微信支付生成并下发。示例值:'1900000109'
        :param operation_type: 操作类型, 枚举值:'OPEN':表示开通商家自定义小票，'CLOSE':表示关闭商家自定义小票。示例值:'OPEN'
        """
        params = {}
        if sub_mchid:
            params.update({'sub_mchid': sub_mchid})
        else:
            raise Exception('sub_mchid is not assigned.')
        if operation_type:
            params.update({'operation_type': operation_type})
        else:
            raise Exception('operation_type is not assigned.')
        path = 'https://api.mch.weixin.qq.com/v3/goldplan/merchants/changecustompagestatus'
        return self._p.core.request(path, method=RequestType.POST, data=params)

    def advertising_filter(self, sub_mchid, advertising_industry_filters):
        """同业过滤标签管理
        :param sub_mchid: 子商户的商户号，由微信支付生成并下发。示例值:'1900000109'
        :param advertising_industry_filters: 同业过滤标签值, 同业过滤标签最少传一个，最多三个。示例值:['SOFTWARE','SECURITY','LOVE_MARRIAGE']
        """
        params = {}
        if sub_mchid:
            params.update({'sub_mchid': sub_mchid})
        else:
            raise Exception('sub_mchid is not assigned.')
        if advertising_industry_filters:
            params.update({'advertising_industry_filters': advertising_industry_filters})
        else:
            raise Exception('advertising_industry_filters is not assigned.')
        path = 'https://api.mch.weixin.qq.com/v3/goldplan/merchants/set-advertising-industry-filter'
        return self._p.core.request(path, method=RequestType.POST, data=params)

    def advertising_open(self, sub_mchid, advertising_industry_filters=None):
        """开通广告展示
        :param sub_mchid: 子商户的商户号，由微信支付生成并下发。示例值:'1900000109'
        :param advertising_industry_filters: 同业过滤标签值, 同业过滤标签最少传一个，最多三个。示例值:['SOFTWARE','SECURITY','LOVE_MARRIAGE']
        """
        params = {}
        if sub_mchid:
            params.update({'sub_mchid': sub_mchid})
        else:
            raise Exception('sub_mchid is not assigned.')
        if advertising_industry_filters:
            params.update({'advertising_industry_filters': advertising_industry_filters})
        else:
            raise Exception('advertising_industry_filters is not assigned.')
        path = 'https://api.mch.weixin.qq.com/v3/goldplan/merchants/open-advertising-show'
        return self._p.core.request(path, method=RequestType.POST, data=params)

    def advertising_close(self, sub_mchid):
        """关闭广告展示
        :param sub_mchid: 子商户的商户号，由微信支付生成并下发。示例值:'1900000109'
        """
        params = {}
        if sub_mchid:
            params.update({'sub_mchid': sub_mchid})
        else:
            raise Exception('sub_mchid is not assigned.')
        path = 'https://api.mch.weixin.qq.com/v3/goldplan/merchants/close-advertising-show'
        return self._p.core.request(path, method=RequestType.POST, data=params)
