using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MisDataSaveDate
{
    #region AGV -> MES 接收请求模型

    /// <summary>
    /// 状态更新请求（到达/离开）
    /// AGV 到达或离开工位时通知 MES
    /// </summary>
    public class ZZAGV_StatusUpdateRequest
    {
        /// <summary>
        /// 工位编号
        /// </summary>
        public string position { get; set; }

        /// <summary>
        /// 类型：1-到达，2-离开
        /// </summary>
        public int type { get; set; }

        /// <summary>
        /// 物料编码/产品编码
        /// </summary>
        public string materialCode { get; set; }

        /// <summary>
        /// AGV车号
        /// </summary>
        public string agvid { get; set; }
    }

    /// <summary>
    /// 动作完成请求（举升/下降）
    /// AGV 完成托盘举升或下降动作后通知 MES
    /// </summary>
    public class ZZAGV_ActionCompleteRequest
    {
        /// <summary>
        /// 工位编号
        /// </summary>
        public string position { get; set; }

        /// <summary>
        /// 类型：1-举升完成，2-下降完成
        /// </summary>
        public int type { get; set; }
    }

    /// <summary>
    /// 故障/报警推送请求
    /// AGV 上报故障或区域故障
    /// </summary>
    public class ZZAGV_AlarmPushRequest
    {
        /// <summary>
        /// AGV车号
        /// </summary>
        public string agvNo { get; set; }

        /// <summary>
        /// 故障代码
        /// </summary>
        public string errorCode { get; set; }

        /// <summary>
        /// 故障信息
        /// </summary>
        public string errorMsg { get; set; }

        /// <summary>
        /// 故障类型：1-AGV故障，2-区域故障
        /// </summary>
        public int type { get; set; }
    }

    /// <summary>
    /// 任务执行结果请求
    /// AGV 告知 MES 任务是否执行成功
    /// </summary>
    public class ZZAGV_TaskResultRequest
    {
        /// <summary>
        /// 任务唯一ID（与下发任务时的 requestTaskId 对应）
        /// </summary>
        public string requestTaskId { get; set; }

        /// <summary>
        /// 执行状态：success-成功，fail-失败
        /// </summary>
        public string status { get; set; }

        /// <summary>
        /// AGV车号
        /// </summary>
        public string agvNo { get; set; }

        /// <summary>
        /// 失败原因（成功时为空）
        /// </summary>
        public string message { get; set; }
    }

    #endregion

    #region MES -> AGV 发送请求模型

    /// <summary>
    /// 下发任务请求
    /// MES 给 AGV 下发搬运任务
    /// </summary>
    public class ZZAGV_AddTaskRequest
    {
        /// <summary>
        /// 任务唯一ID（由 MES 生成）
        /// </summary>
        public string requestTaskId { get; set; }

        /// <summary>
        /// 抬货点/取货位置
        /// </summary>
        public string startPosition { get; set; }

        /// <summary>
        /// 卸货点/目标位置
        /// </summary>
        public string endPosition { get; set; }

        /// <summary>
        /// 产品编码/物料编码
        /// </summary>
        public string materialCode { get; set; }
    }

    /// <summary>
    /// 放行请求
    /// MES 告知 AGV 可以离开当前位置
    /// </summary>
    public class ZZAGV_AllowLeaveRequest
    {
        /// <summary>
        /// 请求ID
        /// </summary>
        public string requestId { get; set; }

        /// <summary>
        /// 当前位置编号
        /// </summary>
        public string position { get; set; }

        /// <summary>
        /// 放行标志（固定为1）
        /// </summary>
        public int allowLeave { get; set; } = 1;
    }

    #endregion

    #region 通用响应模型

    /// <summary>
    /// 西开 AGV 接口通用响应
    /// </summary>
    public class ZZAGV_Response
    {
        /// <summary>
        /// 返回码：0-成功，其他-失败
        /// </summary>
        public int code { get; set; }

        /// <summary>
        /// 返回描述信息
        /// </summary>
        public string desc { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool success { get; set; }

        public ZZAGV_Response()
        {
            code = 0;
            desc = "成功";
            success = true;
        }

        /// <summary>
        /// 设置成功响应
        /// </summary>
        public static ZZAGV_Response Success(string desc = "成功")
        {
            return new ZZAGV_Response
            {
                code = 0,
                desc = desc,
                success = true
            };
        }

        /// <summary>
        /// 设置失败响应
        /// </summary>
        public static ZZAGV_Response Fail(int code, string desc)
        {
            return new ZZAGV_Response
            {
                code = code,
                desc = desc,
                success = false
            };
        }
    }

    #endregion
}
