using Newtonsoft.Json;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BDU.Models
{
    [AddINotifyPropertyChangedInterface]
    public class StepModel
    {

        #region 构造函数

        public StepModel()
        {

        }

        public StepModel(StepModel source)
        {
            if (source == null) return;

            ID = source.ID;
            Index = source.Index;
            Name = source.Name;
            StepType = source.StepType;
            LoopCount = source.LoopCount;
            LoopStartStepId = source.LoopStartStepId;
            OKExpression = source.OKExpression;
            OKGotoStepID = source.OKGotoStepID;
            NGGotoStepID = source.NGGotoStepID;
            Description = source.Description;
            IsUsed = source.IsUsed;

            if (source.Method != null)
            {
                Method = new(source.Method);
            }
            if (source.SubProgram != null)
            {
                SubProgram = new(source.SubProgram);
            }
        }

        #endregion

        public Guid? ID { get; set; } = Guid.NewGuid();

        public bool IsUsed { get; set; } = true;

        public int Index { get; set; }

        public string? Name { get; set; }

        public string? StepType { get; set; }

        public MethodModel? Method { get; set; }

        public ProgramModel? SubProgram { get; set; }

        /// <summary>
        /// 仅LoopStart使用
        /// </summary>
        public int? LoopCount { get; set; }
        
        /// <summary>
        /// 运行时循环计数
        /// </summary>
        [JsonIgnore]
        public int? CurrentLoopCount { get; set; }

        /// <summary>
        /// 仅LoopEnd使用，关联LoopStart
        /// </summary>
        public Guid? LoopStartStepId { get; set; } 

        /// <summary>
        /// 初始：-1  运行中：0  成功：1  异常：2
        /// </summary>
        [JsonIgnore]
        public int Result { get; set; } = -1;

        [JsonIgnore]
        public int? RunTime {  get; set; }

        public string? OKExpression {  get; set; }

        /// <summary>
        /// 默认为0/0不跳转，第一位为OK跳转的步骤序号，第二位为NG跳转的步骤序号
        /// </summary>
        public string GotoSettingString { get; set; } = "";

        public Guid? OKGotoStepID {  get; set; }

        public Guid? NGGotoStepID {  get; set; }

        public string? Description { get; set; }
        
        [JsonIgnore]
        public bool? isBrokenpoint { get; set; }
    }
}
