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

namespace CCDCount.DLL
{
    public class BottingClass
    {
        // 计数，总粒数
        private int KeLiNum = 0;
        // 当前第几瓶
        private int BottNum = 1;
        // 传送带瓶颗粒数量
        private int FirstBottCount = 0;
        // 旋转阀门颗粒数量
        private int SecondBottCount = 0;
        // 通道内颗粒数量
        private int ThirdBottCount = 0;
        // 汽缸阀门上颗粒数量
        private  int FourthBottCount = 0;
        // 一瓶应该多少粒
        private int OneBottNum = 30;

        /// <summary>
        /// 有一粒进入瓶子
        /// </summary>
        /// <returns></returns>
        public bool SetOneActiveToFirstBoot()
        {
            bool result = false;
            KeLiNum++;
            FirstBottCount++;
            if (FirstBottCount >= OneBottNum)
            {
                result = true;
            }
            return result;
        }

        /// <summary>
        ///  有一粒进入旋转阀门
        /// </summary>
        /// <returns></returns>
        public bool SetOneActiveToSecondBoot()
        {
            bool result = false;
            KeLiNum++;
            SecondBottCount++;
            if (SecondBottCount >= OneBottNum)
            {
                result = true;
            }
            return result;
        }

        /// <summary>
        ///  有一粒进入通道
        /// </summary>
        /// <returns></returns>
        public bool SetOneActiveToThirdBoot()
        {
            bool result = false;
            KeLiNum++;
            ThirdBottCount++;
            if (ThirdBottCount >= OneBottNum)
            {
                result = true;
            }
            return result;
        }

        /// <summary>
        ///  有一粒进入汽缸阀门
        /// </summary>
        /// <returns></returns>
        public bool SetOneActiveToFourthBoot()
        {
            bool result = false;
            KeLiNum++;
            FourthBottCount++;
            if (FourthBottCount >= OneBottNum*0.9)
            {
                result = true;
            }
            return result;
        }

        /// <summary>
        ///  计数清零
        /// </summary>
        public void ClearCount()
        {
            KeLiNum = 0;
            BottNum = 1;
            FirstBottCount = 0;
            SecondBottCount = 0;
            ThirdBottCount = 0;
            FourthBottCount = 0;
        }

        /// <summary>
        ///  瓶子计数清零
        /// </summary>
        public void ClearFirstBottCount()
        {
            FirstBottCount = 0;
        }

        /// <summary>
        ///  旋转阀门计数清零
        /// </summary>
        public void ClearSecondBottCount()
        {
            SecondBottCount = 0;
        }

        /// <summary>
        ///  通道计数清零
        /// </summary>
        public void ClearThirdBottCount()
        {
            ThirdBottCount = 0;
        }

        // <summary>
        ///  汽缸阀门计数清零
        /// </summary>
        public void ClearFourthBottCount()
        {
            FourthBottCount = 0;
        }

        /// <summary>
        /// 获取瓶子状态
        /// </summary>
        /// <returns></returns>
        public bool GetFirstBottState()
        {
            return FirstBottCount >= OneBottNum;
        }

        /// <summary>
        /// 获取旋转阀门状态
        /// </summary>
        /// <returns></returns>
        public bool GetSecondBottState()
        {
            return SecondBottCount >= OneBottNum;
        }

        /// <summary>
        /// 获取通道状态
        /// </summary>
        public bool GetThirdBottState()
        {
            return ThirdBottCount >= OneBottNum;
        }

        /// <summary>
        /// 获取汽缸阀门状态
        /// </summary>
        public bool GetFourthBottState()
        {
            return FourthBottCount >= (OneBottNum*0.9);
        }

        /// <summary>
        ///  bottle完成一瓶
        /// </summary>
        public void FinishOnBott()
        {
            BottNum++;
        }

        /// <summary>
        /// 修改每瓶粒数
        /// </summary>
        /// <param name="num"></param>
        public void ChangeOneBottNum(int num)
        {
            OneBottNum = num;
        }

        public void MoveFourthToThirdCount()
        {
            ThirdBottCount += FourthBottCount;
            FourthBottCount = 0;
        }
    }
}
