using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
/// <summary>
/// 子流程
/// </summary>
public class D_SubProcess : I_Enter, I_Exit
{

    #region 变量
    /// <summary>
    /// 自身Id
    /// </summary>
    public int id;

    /// <summary>
    /// 方案Id
    /// </summary>
    public int schemeId;

    /// <summary>
    /// 流程id 
    /// </summary>
    public int processId;

    /// <summary>
    /// 子流程描述
    /// </summary>
    public string subProcessName;

    /// <summary>
    /// 是否有前置条件
    /// </summary>
    public bool isPrecondition;

    /// <summary>
    /// 前置条件
    /// </summary>
    public string precondition;

    /// <summary>
    /// 提示
    /// </summary>
    public string tips;
    #endregion

    /// <summary>
    /// 存放流程的子流程步骤
    /// </summary>
    public List<D_SubProcessStep> subProcessStepes = new List<D_SubProcessStep>();

    /// <summary>
    /// 当前子流程步骤
    /// </summary>
    private D_SubProcessStep currentSubProcessStep;

    /// <summary>
    /// 当前子流程步骤
    /// </summary>
    public D_SubProcessStep CurrentSubProcessStep
    {
        get => currentSubProcessStep;
        set
        {
            currentSubProcessStep = value;
            CurrentSubProcessStepId = currentSubProcessStep.id;
        }
    }

    /// <summary>
    /// 当前子流程步骤Id
    /// </summary>
    private int currentSubProcessStepId;

    /// <summary>
    /// 当前子流程步骤Id
    /// </summary>
    public int CurrentSubProcessStepId
    {
        get => currentSubProcessStepId;
        set
        {
            currentSubProcessStepId = value;
            GameManager.ProcessMgr.subProcessStepId = currentSubProcessStepId;
        }
    }

    /// <summary>
    /// 初始化
    /// </summary>
    public void Init()
    {
        {
            if (subProcessStepes == null || subProcessStepes.Count == 0)
                return;
            CurrentSubProcessStep = subProcessStepes[0];
        }
    }

    /// <summary>
    /// 切换子流程步骤
    /// </summary>
    public void HandoverSubProcessStep(int stepId)
    {
        if (CurrentSubProcessStep != null)
            CurrentSubProcessStep.Exit();
        CurrentSubProcessStep = GetSubProcessStep(stepId);
        CurrentSubProcessStep.Enter();
        UnityEngine.Debug.Log("切换子流程步骤到:" + stepId);
    }

    /// <summary>
    /// 根据id获取 流程对象
    /// </summary>
    /// <param name="processId"></param>
    /// <returns></returns>
    private D_SubProcessStep GetSubProcessStep(int stepId)
    {
        for (int i = 0; i < subProcessStepes.Count; i++)
        {
            if (subProcessStepes[i].id == stepId)
            {
                return subProcessStepes[i];
            }
        }
        return null;
    }

    /// <summary>
    /// 退出子流程
    /// </summary>
    public void Exit()
    {
        UnityEngine.Debug.Log("退出当前子流程:" + id + "_" + subProcessName);
    }

    /// <summary>
    /// 进入子流程
    /// </summary>
    public void Enter()
    {
        UnityEngine.Debug.Log("进入当前子流程:" + id + "_" + subProcessName);
    }
}
