from drf_yasg import openapi

# 设备类型相关Schema
device_type_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'id': openapi.Schema(type=openapi.TYPE_INTEGER, description='设备类型ID'),
        'name': openapi.Schema(type=openapi.TYPE_STRING, description='设备类型名称'),
        'code': openapi.Schema(type=openapi.TYPE_STRING, description='设备类型代码'),
        'description': openapi.Schema(type=openapi.TYPE_STRING, description='设备类型描述'),
        'created_at': openapi.Schema(type=openapi.TYPE_STRING, format='date-time', description='创建时间'),
        'updated_at': openapi.Schema(type=openapi.TYPE_STRING, format='date-time', description='更新时间')
    },
    required=['name', 'code']
)

# 设备批次相关Schema
device_batch_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'id': openapi.Schema(type=openapi.TYPE_INTEGER, description='批次ID'),
        'device_type': openapi.Schema(type=openapi.TYPE_INTEGER, description='设备类型ID'),
        'device_type_name': openapi.Schema(type=openapi.TYPE_STRING, description='设备类型名称'),
        'batch_number': openapi.Schema(type=openapi.TYPE_STRING, description='批次号'),
        'production_date': openapi.Schema(type=openapi.TYPE_STRING, format='date', description='生产日期'),
        'quantity': openapi.Schema(type=openapi.TYPE_INTEGER, description='批次数量'),
        'description': openapi.Schema(type=openapi.TYPE_STRING, description='批次描述'),
        'created_at': openapi.Schema(type=openapi.TYPE_STRING, format='date-time', description='创建时间'),
        'updated_at': openapi.Schema(type=openapi.TYPE_STRING, format='date-time', description='更新时间')
    },
    required=['device_type', 'batch_number', 'production_date', 'quantity']
)

# 设备相关Schema
device_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'id': openapi.Schema(type=openapi.TYPE_INTEGER, description='设备ID'),
        'device_type': openapi.Schema(type=openapi.TYPE_INTEGER, description='设备类型ID'),
        'device_type_name': openapi.Schema(type=openapi.TYPE_STRING, description='设备类型名称'),
        'batch': openapi.Schema(type=openapi.TYPE_INTEGER, description='批次ID'),
        'batch_number': openapi.Schema(type=openapi.TYPE_STRING, description='批次号'),
        'serial_number': openapi.Schema(type=openapi.TYPE_STRING, description='序列号'),
        'device_code': openapi.Schema(type=openapi.TYPE_STRING, description='设备码'),
        'mac_address': openapi.Schema(type=openapi.TYPE_STRING, description='MAC地址'),
        'is_active': openapi.Schema(type=openapi.TYPE_BOOLEAN, description='是否激活'),
        'activated_at': openapi.Schema(type=openapi.TYPE_STRING, format='date-time', description='激活时间'),
        'created_at': openapi.Schema(type=openapi.TYPE_STRING, format='date-time', description='创建时间'),
        'updated_at': openapi.Schema(type=openapi.TYPE_STRING, format='date-time', description='更新时间')
    },
    required=['device_type', 'batch', 'serial_number', 'mac_address']
)

# 设备创建Schema
device_create_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'device_type': openapi.Schema(type=openapi.TYPE_INTEGER, description='设备类型ID'),
        'batch': openapi.Schema(type=openapi.TYPE_INTEGER, description='批次ID'),
        'serial_number': openapi.Schema(type=openapi.TYPE_STRING, description='序列号'),
        'mac_address': openapi.Schema(type=openapi.TYPE_STRING, description='MAC地址')
    },
    required=['device_type', 'batch', 'serial_number', 'mac_address']
)

# 设备批量创建Schema
device_batch_create_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'device_type': openapi.Schema(type=openapi.TYPE_INTEGER, description='设备类型ID'),
        'batch': openapi.Schema(type=openapi.TYPE_INTEGER, description='批次ID'),
        'start_serial': openapi.Schema(type=openapi.TYPE_STRING, description='起始序列号'),
        'count': openapi.Schema(type=openapi.TYPE_INTEGER, description='创建数量'),
        'mac_prefix': openapi.Schema(type=openapi.TYPE_STRING, description='MAC地址前缀（可选）', default='00:11:22')
    },
    required=['device_type', 'batch', 'start_serial', 'count']
)

# 用户设备相关Schema
user_device_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'id': openapi.Schema(type=openapi.TYPE_INTEGER, description='用户设备关联ID'),
        'user': openapi.Schema(type=openapi.TYPE_INTEGER, description='用户ID'),
        'device': openapi.Schema(type=openapi.TYPE_INTEGER, description='设备ID'),
        'device_code': openapi.Schema(type=openapi.TYPE_STRING, description='设备码'),
        'device_type': openapi.Schema(type=openapi.TYPE_STRING, description='设备类型名称'),
        'nickname': openapi.Schema(type=openapi.TYPE_STRING, description='设备昵称'),
        'is_primary': openapi.Schema(type=openapi.TYPE_BOOLEAN, description='是否为主要设备'),
        'bound_at': openapi.Schema(type=openapi.TYPE_STRING, format='date-time', description='绑定时间')
    },
    required=['device']
)

# 设备绑定Schema
device_bind_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'mac_address': openapi.Schema(type=openapi.TYPE_STRING, description='设备MAC地址'),
        'nickname': openapi.Schema(type=openapi.TYPE_STRING, description='设备昵称（可选）'),
        'is_primary': openapi.Schema(type=openapi.TYPE_BOOLEAN, description='是否为主要设备（可选）', default=False)
    },
    required=['mac_address']
)

# Token相关Schema
token_generate_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'expire_time': openapi.Schema(type=openapi.TYPE_INTEGER, description='Token过期时间（秒）')
    }
)

token_response_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'status': openapi.Schema(type=openapi.TYPE_STRING, description='操作状态'),
        'message': openapi.Schema(type=openapi.TYPE_STRING, description='操作结果信息'),
        'data': openapi.Schema(
            type=openapi.TYPE_OBJECT,
            properties={
                'token': openapi.Schema(type=openapi.TYPE_STRING, description='生成的Token'),
                'room_id': openapi.Schema(type=openapi.TYPE_STRING, description='生成的房间ID'),
                'user_id': openapi.Schema(type=openapi.TYPE_STRING, description='用户ID'),
                'app_id': openapi.Schema(type=openapi.TYPE_STRING, description='火山引擎应用ID'),
                'expire_time': openapi.Schema(type=openapi.TYPE_INTEGER, description='Token有效期（秒）'),
                'task_id': openapi.Schema(type=openapi.TYPE_STRING, description='任务ID'),
                'device_code': openapi.Schema(type=openapi.TYPE_STRING, description='设备码'),
                'device_type': openapi.Schema(type=openapi.TYPE_STRING, description='设备类型')
            }
        )
    }
)

# 消息相关Schema
message_send_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'type': openapi.Schema(
            type=openapi.TYPE_STRING, 
            description='消息类型',
            enum=['text', 'weather', 'sing', 'dance']
        ),
        'message': openapi.Schema(
            type=openapi.TYPE_OBJECT,
            description='消息内容，根据type不同有不同的格式'
        )
    },
    required=['message']
)

# 通用响应Schema
success_response_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'status': openapi.Schema(type=openapi.TYPE_STRING, description='操作状态', default='success'),
        'message': openapi.Schema(type=openapi.TYPE_STRING, description='操作结果信息'),
        'data': openapi.Schema(type=openapi.TYPE_OBJECT, description='返回的数据')
    }
)

error_response_schema = openapi.Schema(
    type=openapi.TYPE_OBJECT,
    properties={
        'status': openapi.Schema(type=openapi.TYPE_STRING, description='操作状态', default='error'),
        'message': openapi.Schema(type=openapi.TYPE_STRING, description='错误信息')
    }
)

# 接口参数描述
device_type_param = openapi.Parameter(
    name='id', in_=openapi.IN_PATH,
    description='设备类型ID',
    type=openapi.TYPE_INTEGER, required=True
)

device_batch_param = openapi.Parameter(
    name='id', in_=openapi.IN_PATH,
    description='设备批次ID',
    type=openapi.TYPE_INTEGER, required=True
)

device_param = openapi.Parameter(
    name='id', in_=openapi.IN_PATH,
    description='设备ID',
    type=openapi.TYPE_INTEGER, required=True
)

user_device_param = openapi.Parameter(
    name='id', in_=openapi.IN_PATH,
    description='用户设备关联ID',
    type=openapi.TYPE_INTEGER, required=True
)

mac_address_param = openapi.Parameter(
    name='mac_address', in_=openapi.IN_QUERY,
    description='设备MAC地址',
    type=openapi.TYPE_STRING, required=True
)

expire_time_param = openapi.Parameter(
    name='expire_time', in_=openapi.IN_QUERY,
    description='Token过期时间（秒）',
    type=openapi.TYPE_INTEGER, required=False
) 