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

namespace BPA.MES.Base.Application.Services.AGVService.Dtos
{

    public class Roller_JobRequest
    {
        public string Url { get; set; }

        [Required(ErrorMessage = "[{0}]不能为空")]
        [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")]
        public string AgvCode { get; set; }

        [Required(ErrorMessage = "[{0}]不能为空")]
        [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")]
        public string JobId { get; set; }

        [Required(ErrorMessage = "[{0}]不能为空")]
        [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")]
        public string MsgId { get; set; }

        public bool? Complete { get; set; }
    }

    public class AGVExecuteReplyRequest
    {
        public AgvHeader Header { get; set; }
        public AgvReplyBody Body { get; set; }
    }

    public class AgvReplyBody
    {
        public AGVExecuteReplyDto Event { get; set; }
    }


    public class AGVExecuteReplyMQTT: IMessage
    {
        public AGVExecuteReplyDto Event { get; set; }
        public int MessageId { get; set; }
        public Version MsgVersion { get; set; }
    }

    public class AGVLoadAndUnloadRequest
    {
        public AgvHeader Header { get; set; }
        public AGVLoadAndUnloadBody Body { get; set; }
    }

    public class AGVLoadAndUnloadBody
    {
        public AGVLoadAndUnloadDto Event { get; set; }
    }

    public class AGVLoadAndUnloadMQTT : IMessage
    {
        public AGVLoadAndUnloadDto Event { get; set; }
        public int MessageId { get; set; }
        public Version MsgVersion { get; set; }
    }

    public class AgvBody
    {
        public AgvHeader Header { get; set; }
        public AgvRetrun Body { get; set; }
    }
    public class AgvHeader
    {
        public string RequestId { get; set; }
        public string Timestamp { get; set; }
        public string Version { get; set; }
    }
    public class AgvRetrun
    {
        public string Code { get; set; }

        public bool Success { get; set; }

        public string Message { get; set; }

        public object? Data { get; set; }
    }

    /// <summary>
    /// 任务完成回报Dto
    /// </summary>
    public class AGVExecuteReplyDto
    {
        /// <summary>
        /// 上游系统任务号，全局唯一
        /// </summary>
        public string robotJobId { get; set; }

        /// <summary>
        /// 仓库编号
        /// </summary>
        public long warehouseId { get; set; }

        /// <summary>
        /// 任务快仓系统编号
        /// </summary>
        public string jobId { get; set; }

        /// <summary>
        /// 任务状态
        /// </summary>
        public string state { get; set; }

        /// <summary>
        /// 内部任务类型
        /// </summary>
        public string jobType { get; set; }

        /// <summary>
        /// 数据字段
        /// </summary>
        public PointToPoint jobData { get; set; }

    }

    /// <summary>
    /// 上下料交互请求DTO
    /// </summary>
    public class AGVLoadAndUnloadDto
    {
        /// <summary>
        /// AGV编号
        /// </summary>
        public string agvCode { get; set; }

        /// <summary>
        /// 容器编号，如果一次上/下多个容器，则多个容器用英文逗号分隔
        /// </summary>
        public string containerCode { get; set; }

        /// <summary>
        /// 上游设备ID
        /// </summary>
        public long equipmentId { get; set; }

        /// <summary>
        /// 上游设备ID，多个用英文逗号分隔
        /// </summary>
        public string equipmentIds { get; set; }

        /// <summary>
        /// 快仓任务编号
        /// </summary>
        public string jobId { get; set; }

        /// <summary>
        /// 消息ID
        /// </summary>
        public string msgId { get; set; }

        /// <summary>
        /// 交互阶段LOAD：上料阶段 UNLOAD：下料阶段
        /// </summary>
        public string command { get; set; }

        /// <summary>
        /// 上游任务号
        /// </summary>
        public string robotJobId { get; set; }

    }


    /// <summary>
    /// 货到货
    /// </summary>
    public class GoodsToGoods
    {
        /// <summary>
        /// AGV编号
        /// </summary>
        public string agvCode { get; set; }

        /// <summary>
        /// 容器编号
        /// </summary>
        public string containerCode { get; set; }

        /// <summary>
        /// 上料点位
        /// </summary>
        public string startPointCode { get; set; }

        /// <summary>
        /// 上料货位编号
        /// </summary>
        public string startSlotCode { get; set; }

        /// <summary>
        /// 下料点位
        /// </summary>
        public string targetPointCode { get; set; }

        /// <summary>
        /// 下料货位编号
        /// </summary>
        public string targetSlotCode { get; set; }

        /// <summary>
        /// 是否需要上料交互
        /// </summary>
        public bool loadInteractive { get; set; }
    }

    /// <summary>
    /// 点到点
    /// </summary>
    public class PointToPoint
    {
        /// <summary>
        /// AGV编号
        /// </summary>
        public string agvCode { get; set; }

        /// <summary>
        /// 容器编号
        /// </summary>
        public string containerCode { get; set; }

        /// <summary>
        /// 上料点位
        /// </summary>
        public string startPointCode { get; set; }

        /// <summary>
        /// 下料点位
        /// </summary>
        public string targetPointCode { get; set; }

        /// <summary>
        /// 是否需要上料交互
        /// </summary>
        public bool loadInteractive { get; set; }
    }

    public enum AGVState
    {

        //任务状态：
        //1）货架/货位/点到点货架搬运任务枚举：
        //LIFT_UP_DONE：顶升完成
        //MOVE_BEGIN：开始移动
        //PUT_DOWN_DONE：放下完成
        //DONE：任务完成
        //CANCEL：任务取消
        //ABNORMAL_CANCEL：任务异常取消
        //ABNORMAL_COMPLETED：任务异常完成
        //2）货位到货位/点到点辊筒料箱搬运任务枚举：
        //ROLLER_LOAD_DOING：正在上料
        //ROLLER_LOAD_FINISH：上料完成
        //ROLLER_UNLOAD_DOING：正在下料
        //DONE：下料完成
        //ABNORMAL_CANCEL：任务异常取消
        //ABNORMAL_COMPLETED：任务异常完成
        //3）AGV移动任务枚举：
        //DONE：任务完成
        //CANCEL：任务取消
        //ABNORMAL_CANCEL：任务异常取消
        //ABNORMAL_COMPLETED：任务异常完成
        //4）	纯料箱任务枚举：
        //MOVE_BEGIN:开始移动（仅单插臂或单夹报,2.8.1后）
        //ENTER_STATION：到站
        //DONE：任务完成
        //LOAD_COMPLETED:取料完成
        //UNLOAD_COMPLETED:放料完成
        //ABNORMAL_CANCEL：任务异常取消ABNORMAL_COMPLETED：任务异常完成
        //5）	小皮带任务枚举：
        //DONE：任务完成
        //6）	QuickPick任务枚举：
        //ENTER_STATION：到站
        //DONE：任务完成
        //CANCEL：任务取消
        //LEAVE_STATION离站
        //ROLLBACK 回滚（有其他任务，当前任务可不执行）


        /// <summary>
        /// 顶升完成
        /// </summary>
        LIFT_UP_DONE = 1,

        /// <summary>
        /// 开始移动
        /// </summary>
        MOVE_BEGIN = 2,

        /// <summary>
        /// 放下完成
        /// </summary>
        PUT_DOWN_DONE = 3,

        /// <summary>
        /// 任务完成
        /// </summary>
        DONE = 4,


        /// <summary>
        /// 任务取消
        /// </summary>
        CANCEL = 5,

        /// <summary>
        /// 任务异常取消
        /// </summary>
        ABNORMAL_CANCEL = 6,

        /// <summary>
        /// 任务异常完成
        /// </summary>
        ABNORMAL_COMPLETED = 7

    }

    public enum jobType
    {
        /// <summary>
        /// 1）	辊筒货位到货位搬运
        /// </summary>
        SLOT_ROLLER_MOVE = 1,
        POINT_ROLLER_MOVE=2
    }

    public class KC_Response
    {
        public KC_Response()
        {
            Data = new();
        }
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }
        /// <summary>
        /// 状态码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 返回数据数组
        /// </summary>
        public List<KC_Response_Data> Data { get; set; }
    }
    public class KC_Response_Data
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 消息体
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 任务编号
        /// </summary>
        public string RobotJobId { get; set; }
    }
    /// <summary>
    /// AGV请求
    /// </summary>
    public class KC_ExecuteRequest
    {
        /// <summary>
        /// 快仓api地址
        /// </summary>
        public string Url { get; set; }
        /// <summary>
        /// 任务编码
        /// </summary>
        public string RobotJobId { get; set; }
        /// <summary>
        /// 仓库编码 默认值1
        /// </summary>
        public long WarehouseId { get; set; } = 1;

        public string RobotJobGroupId { get; set; }

        public int? Sequence { get; set; }

        public string RobotJobGroupNum { get; set; }
        /// <summary>
        /// 优先级 0-99 越高越先执行
        /// </summary>
        public int? JobPriority { get; set; }

        public int? JobPriorityType { get; set; }

        public string Deadline { get; set; }

        public string AgvType { get; set; }

        public string AgvEndPoint { get; set; }

        public bool NeedOperation { get; set; }

        public string AgvCode { get; set; }

        public int? TaskCountDown { get; set; } = 0;
        public string BusinessType { get; set; }
        [Required(ErrorMessage = "[{0}]不能为空")]
        [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")]
        //任务类型 用来滚筒点对点 POINT_ROLLER_MOVE n8H7jX
        public string JobType { get; set; } = "POINT_ROLLER_MOVE";
        [Required(ErrorMessage = "[{0}]不能为空")]
        public KC_JobDataRequest? JobData { get; set; }
    }
    /// <summary>
    /// 任务下发起止点信息
    /// </summary>
    public class KC_JobDataRequest
    {
        /// <summary>
        /// 用户自定义信息编号
        /// </summary>
        public string ContainerCode { get; set; }
        /// <summary>
        /// 起点点位
        /// </summary>
        [Required(ErrorMessage = "[{0}]不能为空")]
        [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")]
        public string StartPoint { get; set; }
        /// <summary>
        /// 终点点位
        /// </summary>
        [Required(ErrorMessage = "[{0}]不能为空")]
        [MaxLength(64, ErrorMessage = "[{0}]不能超过64字符")]
        public string EndPoint { get; set; }
        /// <summary>
        /// 上料方式 自动/人工
        /// </summary>
        public bool? AutoLoad { get; set; }
        /// <summary>
        /// 上料交互方式 //接口对接 false
        /// </summary>
        public bool? EnableIOLoad { get; set; } = false;
        /// <summary>
        /// 下料方式 true自动/false人工
        /// </summary>
        public bool? AutoUnload { get; set; }
        /// <summary>
        /// 接口对接 false
        /// </summary>
        public bool? EnableIOUnload { get; set; } = false;
        /// <summary>
        /// 起点设备ID
        /// </summary>
        public long LoadEquipmentId { get; set; }
        /// <summary>
        /// 目标设备ID
        /// </summary>
        public long UnloadEquipmentId { get; set; }

        public long LoadInteractive { get; set; }

        public long LoadHeight { get; set; }

        public long UnloadHeight { get; set; }
    }
}
