namespace Eco.Mods.TechTree
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using Eco.Gameplay.Blocks;
    using Eco.Gameplay.Components;
    using Eco.Gameplay.Components.Auth;
    using Eco.Gameplay.DynamicValues;
    using Eco.Gameplay.Economy;
    using Eco.Gameplay.Housing;
    using Eco.Gameplay.Interactions;
    using Eco.Gameplay.Items;
    using Eco.Gameplay.Minimap;
    using Eco.Gameplay.Objects;
    using Eco.Gameplay.Players;
    using Eco.Gameplay.Property;
    using Eco.Gameplay.Skills;
    using Eco.Gameplay.Systems.TextLinks;
    using Eco.Gameplay.Pipes.LiquidComponents;
    using Eco.Gameplay.Pipes.Gases;
    using Eco.Gameplay.Systems.Tooltip;
    using Eco.Shared;
    using Eco.Shared.Math;
    using Eco.Shared.Localization;
    using Eco.Shared.Serialization;
    using Eco.Shared.Utils;
    using Eco.Shared.View;
    using Eco.Shared.Items;
    using Eco.Gameplay.Pipes;
    using Eco.World.Blocks;
    
    [Serialized]    
    [RequireComponent(typeof(PowerGridComponent))]              
    [RequireComponent(typeof(PowerConsumptionComponent))]   
    [RequireComponent(typeof(OnOffComponent))]                   
    [RequireComponent(typeof(PropertyAuthComponent))]
    [RequireComponent(typeof(MinimapComponent))]
    [RequireComponent(typeof(HousingComponent))]                                                                 
    [RequireComponent(typeof(SolidGroundComponent))]            
    public partial class ElectricGateObject : 
        WorldObject  

    {

    static ElectricGateObject()
        {

        WorldObject.AddOccupancy<ElectricGateObject>(new List<BlockOccupancy>(){

                new BlockOccupancy(new Vector3i(0, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(1, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(2, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(3, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(4, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(5, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(6, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(7, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(8, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(9, 0, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(0, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(1, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(2, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(3, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(4, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(5, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(6, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(7, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(8, 1, 0), typeof(SolidWorldObjectBlock)),
                new BlockOccupancy(new Vector3i(9, 1, 0), typeof(SolidWorldObjectBlock)),
                }); 
        }


        [Serialized] public bool Open = false;
        public override InteractResult OnActRight(InteractionContext context)
        {
            if (context.Parameters != null && context.Parameters.ContainsKey("Moving"))
            {
                this.Open = !this.Open;
                return InteractResult.Success;
            }
           
            return InteractResult.NoOp;

        }
        public override void Tick()
        {
            base.Tick();
            OnOffCheck();
            SetAnimatedState("Moving", Open);
        }

        
        public void OnOffCheck()
        {
            if (this.GetComponent<OnOffComponent>().On)
                this.Open = true;
            else
                this.Open = false;
        }

        public override string FriendlyName { get { return "Electric Sliding Gate"; } } 

        protected override void Initialize()
        {
            this.GetComponent<MinimapComponent>().Initialize("Lights");
            this.GetComponent<HousingComponent>().Set(ElectricGateItem.HousingVal);
            this.GetComponent<PowerConsumptionComponent>().Initialize(500);                      
            this.GetComponent<PowerGridComponent>().Initialize(10, new ElectricPower());        
        }

        public override void Destroy()
        {
            base.Destroy();
        }
       
    }


    [Serialized]
    public partial class ElectricGateItem :
        WorldObjectItem<ElectricGateObject> 
    {
    
        public override string FriendlyName { get { return "Electric Sliding Gate"; } } 
        public override string Description  { get { return  ""; } }

        static ElectricGateItem()
        {


        }

    

        [TooltipChildren] public HousingValue HousingTooltip { get { return HousingVal; } }
        [TooltipChildren] public static HousingValue HousingVal { get { return new HousingValue() 
                                                {
                                                    Category = "General",
                                                    Val = 0,                                   
                                                    TypeForRoomLimit = "Lights", 
                                                    DiminishingReturnPercent = 0.3f    
        };}}
    


    }
    

    [RequiresSkill(typeof(IndustrialEngineeringSkill), 2)]
    public partial class ElectricGateRecipe : Recipe
    {
        public ElectricGateRecipe()
        {
            this.Products = new CraftingElement[]
            {
                new CraftingElement<ElectricGateItem>(),
            };

            this.Ingredients = new CraftingElement[]
            {
                new CraftingElement<SteelItem>(typeof(IndustrialEngineeringEfficiencySkill), 40, IndustrialEngineeringEfficiencySkill.MultiplicativeStrategy),
                new CraftingElement<BrickItem>(typeof(IndustrialEngineeringEfficiencySkill), 80, IndustrialEngineeringEfficiencySkill.MultiplicativeStrategy),
                new CraftingElement<CopperWiringItem>(typeof(IndustrialEngineeringEfficiencySkill), 40, IndustrialEngineeringEfficiencySkill.MultiplicativeStrategy),
                new CraftingElement<GearItem>(6),
                new CraftingElement<ElectricMotorItem>(1),   
            };
            SkillModifiedValue value = new SkillModifiedValue(240, IndustrialEngineeringSpeedSkill.MultiplicativeStrategy, typeof(IndustrialEngineeringSpeedSkill), Localizer.Do("craft time"));
            SkillModifiedValueManager.AddBenefitForObject(typeof(ElectricGateRecipe), Item.Get<ElectricGateItem>().UILink(), value);
            SkillModifiedValueManager.AddSkillBenefit(Item.Get<ElectricGateItem>().UILink(), value);
            this.CraftMinutes = value;
            this.Initialize("Electric Sliding Gate", typeof(ElectricGateRecipe));
            CraftingComponent.AddRecipe(typeof(RoboticAssemblyLineObject), this);
        }
    }
}
