using SicRT.Scheduler;
using MECF.Framework.Common.Equipment;
using System.Collections.Generic;

namespace SicRT.Modules.Schedulers
{
    public class SchedulerModuleFactory
    {
        protected SchedulerTMRobot _tmRobot = new();
        protected SchedulerWaferRobot _waferRobot = new();
        protected SchedulerTrayRobot _trayRobot = new();

        protected SchedulerBuffer _buffer = new(ModuleName.Buffer);
        protected SchedulerLoadLock _load = new(ModuleName.LoadLock);
        protected SchedulerUnLoad _unload = new(ModuleName.UnLoad);
        protected SchedulerAligner _aligner = new(ModuleName.Aligner);
        protected SchedulerPM _pm1 = new(ModuleName.PM1);
        protected SchedulerPM _pm2 = new(ModuleName.PM2);

        protected SchedulerCassette _cassetteAL = new(ModuleName.CassAL);
        protected SchedulerCassette _cassetteAR = new(ModuleName.CassAR);
        protected SchedulerCassette _cassetteBL = new(ModuleName.CassBL);

        protected List<SchedulerPM> _lstPms = new();
        protected List<SchedulerCassette> _lstWaferCassettes = new();

        protected SchedulerModuleFactory()
        {
            _lstPms.AddRange(new[] { _pm1,_pm2 });

            _lstWaferCassettes.AddRange(new[] { _cassetteAL, _cassetteAR});
        }

        protected SchedulerModule GetModule(string name)
        {
            switch (ModuleHelper.Converter(name))
            {
                case ModuleName.Buffer:
                    return _buffer;
                case ModuleName.TMRobot:
                    return _tmRobot;
                case ModuleName.WaferRobot:
                    return _waferRobot;
                case ModuleName.TrayRobot:
                    return _trayRobot;
                case ModuleName.PM1:
                    return _pm1;
                case ModuleName.PM2:
                    return _pm2;
                case ModuleName.CassAL:
                    return _cassetteAL;
                case ModuleName.CassAR:
                    return _cassetteAR;
                case ModuleName.CassBL:
                    return _cassetteBL;
                case ModuleName.LoadLock:
                case ModuleName.Load:
                    return _load;
                case ModuleName.UnLoad:
                    return _unload;
                case ModuleName.Aligner:
                    return _aligner;
            }

            return null;
        }

        protected SchedulerModule GetModule(ModuleName name)
        {
            switch (name)
            {
                case ModuleName.Buffer:
                    return _buffer;
                case ModuleName.TMRobot:
                    return _tmRobot;
                case ModuleName.WaferRobot:
                    return _waferRobot;
                case ModuleName.TrayRobot:
                    return _trayRobot;
                case ModuleName.PM1:
                    return _pm1;
                case ModuleName.PM2:
                    return _pm2;
                case ModuleName.CassAL:
                    return _cassetteAL;
                case ModuleName.CassAR:
                    return _cassetteAR;
                case ModuleName.CassBL:
                    return _cassetteBL;
                case ModuleName.LoadLock:
                case ModuleName.Load:
                    return _load;
                case ModuleName.UnLoad:
                    return _unload;
                case ModuleName.Aligner:
                    return _aligner;
            }

            return null;
        }



        public void Reset()
        {
            _tmRobot.ResetTask();
            foreach (var pm in _lstPms)
            {
                pm.ResetTask();
            }

            _buffer.ResetTask();
        }

    }
}
