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(OnOffComponent))]                   
    [RequireComponent(typeof(PropertyAuthComponent))]
    [RequireComponent(typeof(MinimapComponent))]
    [RequireComponent(typeof(HousingComponent))]                                                                 
    [RequireComponent(typeof(SolidGroundComponent))]            
    public partial class ManualPGateObject : 
        WorldObject  

    {

                static ManualPGateObject()
        {
            WorldObject.AddOccupancy<ManualPGateObject>(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(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(6, 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();
            SetAnimatedState("Moving", Open);
        }

        public override string FriendlyName { get { return "Manual Pivot Gate"; } } 

        protected override void Initialize()
        {
            this.GetComponent<MinimapComponent>().Initialize("Lights");
            this.GetComponent<HousingComponent>().Set(ManualPGateItem.HousingVal);     
        }

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


    [Serialized]
    public partial class ManualPGateItem :
        WorldObjectItem<ManualPGateObject> 
    {
    
        public override string FriendlyName { get { return "Manual Pivot Gate"; } } 
        public override string Description  { get { return  ""; } }

        static ManualPGateItem()
        {

        }



        [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 ManualPGateRecipe : Recipe
    {
        public ManualPGateRecipe()
        {
            this.Products = new CraftingElement[]
            {
                new CraftingElement<ManualPGateItem>(),
            };

            this.Ingredients = new CraftingElement[]
            {
                new CraftingElement<SteelItem>(typeof(IndustrialEngineeringEfficiencySkill), 40, IndustrialEngineeringEfficiencySkill.MultiplicativeStrategy),
                new CraftingElement<BrickItem>(typeof(IndustrialEngineeringEfficiencySkill), 80, IndustrialEngineeringEfficiencySkill.MultiplicativeStrategy),
                new CraftingElement<GearItem>(6),
            };
            SkillModifiedValue value = new SkillModifiedValue(240, IndustrialEngineeringSpeedSkill.MultiplicativeStrategy, typeof(IndustrialEngineeringSpeedSkill), Localizer.DoStr("craft time"));
            SkillModifiedValueManager.AddBenefitForObject(typeof(ManualPGateRecipe), Item.Get<ManualPGateItem>().UILink(), value);
            SkillModifiedValueManager.AddSkillBenefit(Item.Get<ManualPGateItem>().UILink(), value);
            this.CraftMinutes = value;
            this.Initialize("Manual Pivot Gate", typeof(ManualPGateRecipe));
            CraftingComponent.AddRecipe(typeof(RoboticAssemblyLineObject), this);
        }
    }
}
