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 ElectricPGateObject : 
        WorldObject  

    {
            [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;
        }
    protected override void Initialize()
        
        {
            this.GetComponent<MinimapComponent>().Initialize("Lights");
            this.GetComponent<HousingComponent>().Set(ElectricPGateItem.HousingVal);                     
            this.GetComponent<PowerConsumptionComponent>().Initialize(500);                      
            this.GetComponent<PowerGridComponent>().Initialize(10, new ElectricPower());        

        }
    }


    [Serialized]
    public partial class ElectricPGateItem :
        WorldObjectItem<ElectricPGateObject> 
    {
        
        public override string FriendlyName { get { return "Electric Pivot Gate"; } } 
        public override string Description  { get { return  ""; } }


        static ElectricPGateItem()
        {
            WorldObject.AddOccupancy<ElectricPGateObject>(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)),
                });
        }


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

            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.Do("craft time"));
            SkillModifiedValueManager.AddBenefitForObject(typeof(ElectricPGateRecipe), Item.Get<ElectricPGateItem>().UILink(), value);
            SkillModifiedValueManager.AddSkillBenefit(Item.Get<ElectricPGateItem>().UILink(), value);
            this.CraftMinutes = value;
            this.Initialize("Electric Pivot Gate", typeof(ElectricPGateRecipe));
            CraftingComponent.AddRecipe(typeof(FactoryObject), this);
        }
    }
}
