using System;
using MrWu.Debug;

namespace Server.Core
{
    public class CoroutineLock : Reference
    {
        public int Type
        {
            get;
            private set;
        }

        public long Key
        {
            get;
            private set;
        }

        public int Level
        {
            get;
            private set;
        }

        public CoroutineLockManager CoroutineLockManager
        {
            get;
            private set;
        }

        public static CoroutineLock Create(int type,long key,int level,CoroutineLockManager coroutineLockManager)
        {
            CoroutineLock coroutineLock = ReferencePool.Fetch<CoroutineLock>();
            coroutineLock.Type = type;
            coroutineLock.Key = key;
            coroutineLock.Level = level;
            coroutineLock.CoroutineLockManager = coroutineLockManager;
            return coroutineLock;
        }

        public override void Dispose()
        {
            Debug.Log("CoroutineLock Dispose!");
            CoroutineLockManager.RunNextCoroutine(this.Type, this.Key, this.Level + 1);
            this.Type = CoroutineLockType.None;
            this.Key = 0;
            this.Level = 0;
            this.CoroutineLockManager = null;
            
            ReferencePool.Recycle(this);
        }
    }
}