using MainShell.Common;
using MainShell.Filewritable;
using MaxwellControl.Controls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MainShell.DeviceMaintance.Model
{
    public enum MaintanceType
    {
        针尖维护 = 1,
        相机校验 = 2,
        针印验证 = 3,
    }
    public class MaintanceRecord
    {
        /// <summary>
        /// 设备编号
        /// </summary>
        public string DeviceId { get; set; }
        /// <summary>
        /// 设备名称
        /// </summary>
        public string DeviceName { get; set; }
        /// <summary>
        /// 维护时间
        /// </summary>
        public DateTime MaintanceTime { get; set; }
        /// <summary>
        /// 维护内容
        /// </summary>
        public MaintanceType MaintanceType { get; set; }

        public void WriteToFile(string info)
        {
            try
            {
                if (!Directory.Exists(Paths.MaintanceRecordDir))
                {
                    Directory.CreateDirectory(Paths.MaintanceRecordDir);
                }
                string filePath = Path.Combine(Paths.MaintanceRecordDir, $"{MaintanceType}_MaintanceRecord.txt");
                using (var writer = new System.IO.StreamWriter(filePath, true))
                {
                    if (!File.Exists(filePath))
                    {
                        writer.WriteLine("设备ID,日期,信息");
                    }
                    writer.WriteLine($"{DeviceId},{DateTime.Now}: {info}");
                    writer.Flush();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"写入文件失败: {ex.Message}");
            }
        }
    }

}
