using System.Collections.Generic;
using XP.Hardware.Detector.Abstractions.Enums;

namespace XP.Hardware.Detector.Config
{
    /// <summary>
    /// Varex 探测器配置类 | Varex detector configuration class
    /// 包含 Varex 专属的配置参数
    /// </summary>
    public class VarexDetectorConfig : DetectorConfig
    {
        /// <summary>
        /// Binning 模式 | Binning mode
        /// </summary>
        public BinningMode BinningMode { get; set; } = BinningMode.Bin1x1;

        /// <summary>
        /// 增益模式 | Gain mode
        /// </summary>
        public GainMode GainMode { get; set; } = GainMode.Low;

        /// <summary>
        /// 曝光时间（毫秒）| Exposure time (milliseconds)
        /// </summary>
        public uint ExposureTime { get; set; } = 100;

        /// <summary>
        /// ROI 起始 X 坐标 | ROI start X coordinate
        /// </summary>
        public uint RoiX { get; set; } = 0;

        /// <summary>
        /// ROI 起始 Y 坐标 | ROI start Y coordinate
        /// </summary>
        public uint RoiY { get; set; } = 0;

        /// <summary>
        /// ROI 宽度 | ROI width
        /// </summary>
        public uint RoiWidth { get; set; } = 0;

        /// <summary>
        /// ROI 高度 | ROI height
        /// </summary>
        public uint RoiHeight { get; set; } = 0;

        /// <summary>
        /// Varex 支持 1×1、2×2、4×4 三种 Binning | Varex supports 1×1, 2×2, 4×4 binning
        /// </summary>
        public override List<BinningOption> GetSupportedBinnings()
        {
            return new List<BinningOption>
            {
                new BinningOption("1×1", 0),
                new BinningOption("2×2", 1),
                new BinningOption("3×3", 2),
                new BinningOption("4×4", 3),
            };
        }

        /// <summary>
        /// Varex PGA 范围 2-7 | Varex PGA range 2-7
        /// </summary>
        public override List<int> GetSupportedPgaValues()
        {
            return new List<int> { 2, 3, 4, 5, 6, 7 };
        }

        /// <summary>
        /// Varex 各 Binning 模式最大帧率 | Varex max frame rate per binning mode
        /// </summary>
        public override decimal GetMaxFrameRate(int binningIndex) => binningIndex switch
        {
            0 => 15m,   // 1×1
            1 => 30m,   // 2×2
            2 => 45m,   // 3×3
            3 => 60m,   // 4×4
            _ => 15m
        };

        /// <summary>
        /// Varex 4343N 各 Binning 模式的图像规格 | Varex 4343N image spec per binning mode
        /// 像素尺寸和分辨率映射关系，供重建 PC 使用
        /// </summary>
        public override BinningImageSpec GetImageSpec(int binningIndex) => binningIndex switch
        {
            0 => new BinningImageSpec(0.139, 0.139, 3072, 3060),  // 1×1
            1 => new BinningImageSpec(0.278, 0.278, 1536, 1530),  // 2×2
            2 => new BinningImageSpec(0.417, 0.417, 1024, 1020),  // 3×3
            3 => new BinningImageSpec(0.556, 0.556, 768, 765),    // 4×4
            _ => new BinningImageSpec(0.139, 0.139, 3072, 3060)
        };
    }
}
