# coding=utf8

# Copyright 2018 JDCLOUD.COM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# NOTE: This class is auto generated by the jdcloud code generator program.

from argparse import RawTextHelpFormatter
from jdcloud_cli.cement.ext.ext_argparse import expose
from jdcloud_cli.controllers.base_controller import BaseController
from jdcloud_cli.client_factory import ClientFactory
from jdcloud_cli.parameter_builder import collect_user_args, collect_user_headers
from jdcloud_cli.printer import Printer
from jdcloud_cli.skeleton import Skeleton


class IothubController(BaseController):
    class Meta:
        label = 'iothub'
        help = 'JCLOUD IoT Hub API'
        description = '''
        iothub cli 子命令，API related to IoT Hub。
        OpenAPI文档地址为：https://docs.jdcloud.com/cn/xxx/api/overview
        '''
        stacked_on = 'base'
        stacked_type = 'nested'

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域ID """, dest='regionId',  required=False)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--page-number'], dict(help="""(int) 页码, 默认为1, 取值范围：[1,∞) """, dest='pageNumber', type=int, required=False)),
            (['--page-size'], dict(help="""(int) 分页大小，默认为10，取值范围：[10,100] """, dest='pageSize', type=int, required=False)),
            (['--filters'], dict(help="""(array: filter) abilityName-功能名称，精确匹配; abilityType-功能类型，精确匹配;  """, dest='filters',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查看产品功能列表接口 ''',
        description='''
            查看产品功能列表接口。

            示例: jdc iothub list-product-abilities  --product-key xxx
        ''',
    )
    def list_product_abilities(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.ListProductAbilitiesRequest import ListProductAbilitiesRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = ListProductAbilitiesRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域ID """, dest='regionId',  required=False)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--thing-model'], dict(help="""(object) 物模型JSON """, dest='thingModel',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 导入物模型 ''',
        description='''
            导入物模型。

            示例: jdc iothub import-thing-model  --product-key xxx --thing-model '{"":""}'
        ''',
    )
    def import_thing_model(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.ImportThingModelRequest import ImportThingModelRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = ImportThingModelRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域ID """, dest='regionId',  required=False)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 导出物模型 ''',
        description='''
            导出物模型。

            示例: jdc iothub export-thing-model  --product-key xxx
        ''',
    )
    def export_thing_model(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.ExportThingModelRequest import ExportThingModelRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = ExportThingModelRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--identifier'], dict(help="""(string) 设备唯一标识 """, dest='identifier',  required=True)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查看设备影子 ''',
        description='''
            查看设备影子。

            示例: jdc iothub describe-thing-shadow  --identifier xxx --product-key xxx
        ''',
    )
    def describe_thing_shadow(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.DescribeThingShadowRequest import DescribeThingShadowRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeThingShadowRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--identifier'], dict(help="""(string) 设备唯一标识 """, dest='identifier',  required=True)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--state'], dict(help="""(object) 运行状态 """, dest='state',  required=False)),
            (['--version'], dict(help="""(int) 设备影子版本,当前版本加1，当前版本默认其实版本为-1; 用户主动更新版本号时，设备影子会检查请求中的主动更新版本号是否大于当前版本号。; 如果大于当前版本号，则更新设备影子，并将影子版本值更新到请求的版本中，反之则会拒绝更新设备影子。; 影子版本参数为Integer型; 取值范围：0到2147483647(2的31次方-1); 当取值达到最大值2147483647(2的31次方-1)时，请求中的主动更新版本号应为-1;  """, dest='version', type=int, required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 更新设备影子的期望值 ''',
        description='''
            更新设备影子的期望值。

            示例: jdc iothub update-thing-shadow  --identifier xxx --product-key xxx
        ''',
    )
    def update_thing_shadow(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.UpdateThingShadowRequest import UpdateThingShadowRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = UpdateThingShadowRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--identifier'], dict(help="""(string) 设备唯一标识 """, dest='identifier',  required=True)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--name'], dict(help="""(string) 服务名称 """, dest='name',  required=False)),
            (['--input'], dict(help="""(object) 输入参数,object的key为参数名称，value为参数值 """, dest='input',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 设备服务调用 ''',
        description='''
            设备服务调用。

            示例: jdc iothub invoke-thing-service  --identifier xxx --product-key xxx
        ''',
    )
    def invoke_thing_service(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.InvokeThingServiceRequest import InvokeThingServiceRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = InvokeThingServiceRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--device-name'], dict(help="""(string) 设备名称，模糊匹配 """, dest='deviceName',  required=False)),
            (['--status'], dict(help="""(int) 设备状态 0-未激活，1-激活离线，2-激活在线 """, dest='status', type=int, required=False)),
            (['--product-key'], dict(help="""(string) 设备所归属的产品Key """, dest='productKey',  required=False)),
            (['--device-type'], dict(help="""(int) 设备类型，同产品类型，0-设备，1-网关 """, dest='deviceType', type=int, required=False)),
            (['--now-page'], dict(help="""(int) 当前页数 """, dest='nowPage', type=int, required=False)),
            (['--page-size'], dict(help="""(int) 每页的数据条数 """, dest='pageSize', type=int, required=False)),
            (['--order'], dict(help="""(string) 排序关键字--name,type,productKey,status--最多支持一个字段 """, dest='order',  required=False)),
            (['--direction'], dict(help="""(string) 顺序，升序降序--asc,desc """, dest='direction',  required=False)),
            (['--parent-id'], dict(help="""(string) 父设备Id """, dest='parentId',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 分页查询设备信息,支持一个或多个条件 ''',
        description='''
            分页查询设备信息,支持一个或多个条件。

            示例: jdc iothub query-device-page 
        ''',
    )
    def query_device_page(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.QueryDevicePageRequest import QueryDevicePageRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = QueryDevicePageRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--device-id'], dict(help="""(string) 设备Id """, dest='deviceId',  required=True)),
            (['--model'], dict(help="""(string) 设备型号 """, dest='model',  required=False)),
            (['--manufacturer'], dict(help="""(string) 设备厂商 """, dest='manufacturer',  required=False)),
            (['--description'], dict(help="""(string) 设备描述 """, dest='description',  required=False)),
            (['--status'], dict(help="""(int) 设备状态 """, dest='status', type=int, required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 修改设备详情 ''',
        description='''
            修改设备详情。

            示例: jdc iothub update-device  --device-id xxx
        ''',
    )
    def update_device(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.UpdateDeviceRequest import UpdateDeviceRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = UpdateDeviceRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--device-name'], dict(help="""(string) 设备名称 """, dest='deviceName',  required=False)),
            (['--product-key'], dict(help="""(string) 设备所归属的产品 """, dest='productKey',  required=False)),
            (['--model'], dict(help="""(string) 设备型号 """, dest='model',  required=False)),
            (['--manufacturer'], dict(help="""(string) 厂商 """, dest='manufacturer',  required=False)),
            (['--description'], dict(help="""(string) 设备描述 """, dest='description',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 注册单个设备并返回秘钥信息 ''',
        description='''
            注册单个设备并返回秘钥信息。

            示例: jdc iothub add-device 
        ''',
    )
    def add_device(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.AddDeviceRequest import AddDeviceRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = AddDeviceRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--device-name'], dict(help="""(string) 设备名称 """, dest='deviceName',  required=True)),
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查询设备详情 ''',
        description='''
            查询设备详情。

            示例: jdc iothub query-device-detail  --device-name xxx --product-key xxx
        ''',
    )
    def query_device_detail(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.QueryDeviceDetailRequest import QueryDeviceDetailRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = QueryDeviceDetailRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--device-name'], dict(help="""(string) 设备名称 """, dest='deviceName',  required=True)),
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 删除设备 ''',
        description='''
            删除设备。

            示例: jdc iothub remove-device  --device-name xxx --product-key xxx
        ''',
    )
    def remove_device(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.RemoveDeviceRequest import RemoveDeviceRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = RemoveDeviceRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 设备归属的实例所在区域 """, dest='regionId',  required=False)),
            (['--device-id'], dict(help="""(string) 设备Id """, dest='deviceId',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 删除设备 ''',
        description='''
            删除设备。

            示例: jdc iothub remove-device-by-id  --device-id xxx
        ''',
    )
    def remove_device_by_id(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.RemoveDeviceByIdRequest import RemoveDeviceByIdRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = RemoveDeviceByIdRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域ID """, dest='regionId',  required=False)),
            (['--page-number'], dict(help="""(int) 页码, 默认为1, 取值范围：[1,∞) """, dest='pageNumber', type=int, required=False)),
            (['--page-size'], dict(help="""(int) 分页大小，默认为10，取值范围：[10,100] """, dest='pageSize', type=int, required=False)),
            (['--filters'], dict(help="""(array: filter) productName-产品名称，精确匹配，支持单个; productKey-产品key，精确匹配，支持单个; productType-产品类型，精确匹配，支持单个;  """, dest='filters',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查看产品列表接口 ''',
        description='''
            查看产品列表接口。

            示例: jdc iothub list-products 
        ''',
    )
    def list_products(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.ListProductsRequest import ListProductsRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = ListProductsRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域ID """, dest='regionId',  required=False)),
            (['--product-name'], dict(help="""(string) 产品名称，名称不可为空，3-30个字符，只支持汉字、英文字母、数字、下划线“_”及中划线“-”，必须以汉字、英文字母及数字开头结尾 """, dest='productName',  required=True)),
            (['--product-type'], dict(help="""(int) 节点类型，取值：; 0：设备。设备不能挂载子设备。可以直连物联网平台，也可以作为网关的子设备连接物联网平台; 1：网关。网关可以挂载子设备，具有子设备管理模块，维持子设备的拓扑关系，和将拓扑关系同步到物联网平台;  """, dest='productType', type=int, required=True)),
            (['--product-description'], dict(help="""(string) 产品描述，80字符以内 """, dest='productDescription',  required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 新建产品 ''',
        description='''
            新建产品。

            示例: jdc iothub create-product  --product-name xxx --product-type 5
        ''',
    )
    def create_product(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.CreateProductRequest import CreateProductRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = CreateProductRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域ID """, dest='regionId',  required=False)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 查看产品 ''',
        description='''
            查看产品。

            示例: jdc iothub describe-product  --product-key xxx
        ''',
    )
    def describe_product(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.DescribeProductRequest import DescribeProductRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DescribeProductRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域ID """, dest='regionId',  required=False)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--product-name'], dict(help="""(string) 产品名称，名称不可为空，3-30个字符，只支持汉字、英文字母、数字、下划线“_”及中划线“-”，必须以汉字、英文字母及数字开头结尾 """, dest='productName',  required=False)),
            (['--product-description'], dict(help="""(string) 产品描述，80字符以内 """, dest='productDescription',  required=False)),
            (['--dynamic-register'], dict(help="""(int) 动态注册,0:关闭，1:开启 """, dest='dynamicRegister', type=int, required=False)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 修改产品 ''',
        description='''
            修改产品。

            示例: jdc iothub update-product  --product-key xxx
        ''',
    )
    def update_product(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.UpdateProductRequest import UpdateProductRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = UpdateProductRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--region-id'], dict(help="""(string) 地域ID """, dest='regionId',  required=False)),
            (['--product-key'], dict(help="""(string) 产品Key """, dest='productKey',  required=True)),
            (['--input-json'], dict(help='(json) 以json字符串或文件绝对路径形式作为输入参数。\n字符串方式举例：--input-json \'{"field":"value"}\';\n文件格式举例：--input-json file:///xxxx.json', dest='input_json', required=False)),
            (['--jdcloud-header'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='jdcloudHeaders', required=False)),
            (['--headers'], dict(help="""(json) 用户自定义Header，举例：'{"x-jdcloud-security-token":"abc","test":"123"}'""", dest='headers', required=False)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 删除产品 ''',
        description='''
            删除产品。

            示例: jdc iothub delete-product  --product-key xxx
        ''',
    )
    def delete_product(self):
        client_factory = ClientFactory('iothub')
        client = client_factory.get(self.app)
        if client is None:
            return

        try:
            from jdcloud_sdk.services.iothub.apis.DeleteProductRequest import DeleteProductRequest
            params_dict = collect_user_args(self.app)
            headers = collect_user_headers(self.app)
            req = DeleteProductRequest(params_dict, headers)
            resp = client.send(req)
            Printer.print_result(resp)
        except ImportError:
            print('{"error":"This api is not supported, please use the newer version"}')
        except Exception as e:
            print(e)

    @expose(
        arguments=[
            (['--api'], dict(help="""(string) api name """, choices=['list-product-abilities','import-thing-model','export-thing-model','describe-thing-shadow','update-thing-shadow','invoke-thing-service','query-device-page','update-device','add-device','query-device-detail','remove-device','remove-device-by-id','list-products','create-product','describe-product','update-product','delete-product',], required=True)),
        ],
        formatter_class=RawTextHelpFormatter,
        help=''' 生成单个API接口的json骨架空字符串 ''',
        description='''
            生成单个API接口的json骨架空字符串。

            示例: jdc nc generate-skeleton --api describeContainer ''',
    )
    def generate_skeleton(self):
        skeleton = Skeleton('iothub', self.app.pargs.api)
        skeleton.show()
