using System;
using System.Collections.Generic;

namespace NavisworksTransport.Core.Models
{
    /// <summary>
    /// 时标配置 - 一套完整的时间标签方案
    /// </summary>
    public class TimeTagProfile
    {
        /// <summary>
        /// 配置ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 关联路径ID
        /// </summary>
        public string RouteId { get; set; }

        /// <summary>
        /// 配置名称（如：叉车满载）
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 默认速度 m/s
        /// </summary>
        public double DefaultSpeed { get; set; }

        /// <summary>
        /// 转弯速度比例（0.5=半速）
        /// </summary>
        public double TurnSpeedRatio { get; set; }

        /// <summary>
        /// 事件节点列表
        /// </summary>
        public List<TimeTagEvent> Events { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// 总时间（从最后一个事件获取）
        /// </summary>
        public double TotalTime => Events?.Count > 0 ? Events[Events.Count - 1].CumulativeTime : 0;

        public TimeTagProfile()
        {
            Id = Guid.NewGuid().ToString();
            Events = new List<TimeTagEvent>();
            DefaultSpeed = 1.0;
            TurnSpeedRatio = 0.5;
            CreatedAt = DateTime.Now;
        }
    }

    /// <summary>
    /// 时间事件节点
    /// </summary>
    public class TimeTagEvent
    {
        /// <summary>
        /// 事件ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 所属配置ID
        /// </summary>
        public string ProfileId { get; set; }

        /// <summary>
        /// 关联路径点ID（可选）
        /// </summary>
        public string PointId { get; set; }

        /// <summary>
        /// 距起点距离（米）
        /// </summary>
        public double Distance { get; set; }

        /// <summary>
        /// 事件类型
        /// </summary>
        public EventType Type { get; set; }

        /// <summary>
        /// 事件名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 等待时间（秒）
        /// </summary>
        public double WaitTime { get; set; }

        /// <summary>
        /// 动作时间（秒）
        /// </summary>
        public double ActionTime { get; set; }

        /// <summary>
        /// 累计时间（自动计算）
        /// </summary>
        public double CumulativeTime { get; set; }

        /// <summary>
        /// 到达速度限制（可选）
        /// </summary>
        public double? ArriveSpeed { get; set; }

        /// <summary>
        /// 离开速度限制（可选）
        /// </summary>
        public double? LeaveSpeed { get; set; }

        /// <summary>
        /// 排序序号
        /// </summary>
        public int SortOrder { get; set; }

        public TimeTagEvent()
        {
            Id = Guid.NewGuid().ToString();
            Type = EventType.Pass;
            Name = "途经点";
        }
    }

    /// <summary>
    /// 事件类型枚举
    /// </summary>
    public enum EventType
    {
        /// <summary>
        /// 起点
        /// </summary>
        Start,

        /// <summary>
        /// 途经点
        /// </summary>
        Pass,

        /// <summary>
        /// 转弯
        /// </summary>
        Turn,

        /// <summary>
        /// 等待
        /// </summary>
        Wait,

        /// <summary>
        /// 装货
        /// </summary>
        Load,

        /// <summary>
        /// 卸货
        /// </summary>
        Unload,

        /// <summary>
        /// 终点
        /// </summary>
        End
    }
}
