#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
呼叫器设备模型模块
定义呼叫器设备相关的请求和响应模型
"""

from typing import List, Optional
from pydantic import BaseModel, Field

# 定义按钮模型
class CallDeviceButtonModel(BaseModel):
    """呼叫器设备按钮模型"""
    signal_name: str = Field(..., description="信号名称", min_length=1, max_length=100)
    signal_type: int = Field(..., description="信号类型 1:按钮 2:灯")
    signal_length: str = Field(..., description="信号长度")
    register_address: str = Field(..., description="寄存器地址")
    function_code: Optional[str] = Field(..., description="功能码")
    remark: Optional[str] = Field(None, description="备注")
    vwed_task_id: Optional[str] = Field(None, description="按下灯亮绑定的VWED任务ID")
    long_vwed_task_id: Optional[str] = Field(None, description="长按取消后触发VWED任务ID")

# 定义呼叫器模型
class CallDeviceModel(BaseModel):
    """呼叫器设备模型"""
    protocol: str = Field(..., description="协议类型")
    brand: str = Field("艾智威", description="品牌", min_length=1, max_length=50)
    ip: str = Field(..., description="IP地址")
    port: int = Field(..., description="端口号")
    device_name: str = Field(..., description="设备名称", min_length=1, max_length=100)
    status: int = Field(0, description="状态(0:禁用,1:启用)")
    slave_id: Optional[str] = Field("1", description="从机ID")
    function_code: Optional[str] = Field("4x", description="功能码")
    buttons: List[CallDeviceButtonModel] = Field([], description="呼叫器按钮列表")

# 定义删除设备请求模型
class DeleteDeviceRequest(BaseModel):
    ids: List[str]

# 定义导出设备请求模型
class ExportDevicesRequest(BaseModel):
    """导出呼叫器设备请求模型"""
    ids: List[str] = Field(..., description="要导出的呼叫器设备ID列表")

# 定义导入设备结果模型
class ImportDeviceResult(BaseModel):
    """导入呼叫器设备结果模型"""
    success_count: int = Field(0, description="成功导入数量")
    failed_count: int = Field(0, description="导入失败数量")
    failed_devices: List[dict] = Field([], description="导入失败的设备信息")
    imported_devices: List[dict] = Field([], description="成功导入的设备信息")
