using System.ComponentModel.DataAnnotations;

namespace SHH.CameraSdk;

/// <summary>
/// 设备配置更新传输对象
/// <para>用于接收前端的编辑请求，支持部分更新（字段为 null 表示不修改）</para>
/// <para>自动区分 <b>冷更新参数</b>（需重启连接）和 <b>热更新参数</b>（无感生效）</para>
/// </summary>
public class DeviceUpdateDto
{
    // ==============================================================================
    // 1. 冷更新参数 (Cold Update)
    // 修改此类参数涉及物理连接变更，后端会自动执行 "Stop -> Update -> Start" 流程
    // ==============================================================================

    /// <summary>摄像头IP地址</summary>
    [RegularExpression(@"^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$",
        ErrorMessage = "请输入合法的IPv4地址")]
    public string? IpAddress { get; set; }

    /// <summary>SDK端口 (如海康 8000)</summary>
    [Range(1, 65535, ErrorMessage = "端口号必须在 1-65535 范围内")]
    public ushort? Port { get; set; }

    /// <summary>登录用户名</summary>
    [MaxLength(32, ErrorMessage = "用户名长度不能超过 32 个字符")]
    public string? Username { get; set; }

    /// <summary>登录密码</summary>
    [MaxLength(64, ErrorMessage = "密码长度不能超过 64 个字符")]
    public string? Password { get; set; }

    /// <summary>通道号 (默认 1)</summary>
    [Range(1, 32, ErrorMessage = "通道号必须在 1-32 范围内")]
    public int? ChannelIndex { get; set; }

    /// <summary>摄像头品牌类型 (0:Hik, 1:Dahua...)</summary>
    [Range(0, 10, ErrorMessage = "品牌类型值必须在 0-10 范围内")]
    public int? Brand { get; set; }

    /// <summary>RTSP流地址 (非SDK模式下使用)</summary>
    [MaxLength(256, ErrorMessage = "RTSP地址长度不能超过 256 个字符")]
    public string RtspPath { get; set; }
        = string.Empty;

    /// <summary>渲染句柄 (IntPtr 的 Long 形式)</summary>
    [Range(0, long.MaxValue, ErrorMessage = "渲染句柄必须是非负整数")]
    public long RenderHandle { get; set; }

    // ==============================================================================
    // 2. 热更新参数 (Hot Update)
    // 修改此类参数仅刷新运行时状态，不中断物理连接，无感生效
    // ==============================================================================

    /// <summary>设备名称/别名</summary>
    [MaxLength(64, ErrorMessage = "设备名称长度不能超过 64 个字符")]
    public string? Name { get; set; }

    /// <summary>安装位置描述</summary>
    [MaxLength(128, ErrorMessage = "安装位置长度不能超过 128 个字符")]
    public string? Location { get; set; }

    /// <summary>码流类型 (0:主码流, 1:子码流)</summary>
    [Range(0, 1, ErrorMessage = "码流类型只能是 0(主码流) 或 1(子码流)")]
    public int? StreamType { get; set; }

    /// <summary>关联的主板IP (用于联动控制)</summary>
    [RegularExpression(@"^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)?$",
        ErrorMessage = "请输入合法的IPv4地址")]
    public string MainboardIp { get; set; }
        = string.Empty;

    /// <summary>关联的主板端口</summary>
    [Range(1, 65535, ErrorMessage = "主板端口号必须在 1-65535 范围内")]
    public int MainboardPort { get; set; }

    // ==============================================================================
    // 3. 图像处理参数 (Image Processing - Hot Update)
    // 影响解码后的 SmartFrame 数据格式
    // ==============================================================================

    /// <summary>是否允许压缩 (影响传输带宽)</summary>
    public bool? AllowCompress { get; set; }

    /// <summary>是否允许放大 (影响渲染质量)</summary>
    public bool? AllowExpand { get; set; }

    /// <summary>目标分辨率 (格式如 "1920x1080"，空则保持原图)</summary>
    [RegularExpression(@"^\d+x\d+$", ErrorMessage = "分辨率格式必须为 宽度x高度 (如 1920x1080)")]
    public string? TargetResolution { get; set; }

    /// <summary>是否启用图像增强 (去噪/锐化等)</summary>
    public bool? EnhanceImage { get; set; }

    /// <summary>是否转为灰度图 (用于 AI 纯分析场景加速)</summary>
    public bool? UseGrayscale { get; set; }
}