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

    {

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

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

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

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


    [Serialized]
    public partial class ManualGateItem :
        WorldObjectItem<ManualGateObject> 
    {
    
        public override string FriendlyName { get { return "Manual Sliding Gate"; } } 
        public override string Description  { get { return  "Ouvrer la porte les gars !!"; } }

        static ManualGateItem()
        {

        }

    

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

            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(ManualGateRecipe), Item.Get<ManualGateItem>().UILink(), value);
            SkillModifiedValueManager.AddSkillBenefit(Item.Get<ManualGateItem>().UILink(), value);
            this.CraftMinutes = value;
            this.Initialize("Manual Sliding Gate", typeof(ManualGateRecipe));
            CraftingComponent.AddRecipe(typeof(RoboticAssemblyLineObject), this);
        }
    }
}
