// Copyright (c) Strange Loop Games. All rights reserved.
// See LICENSE file in the project root for full license information.

namespace Eco.Mods.TechTree
{
    using Eco.Core.Items;
    using Eco.Gameplay.Components;
    using Eco.Gameplay.Components.Auth;
    using Eco.Gameplay.Interactions;
    using Eco.Gameplay.Items;
    using Eco.Gameplay.Objects;
    using Eco.Shared.Localization;
    using Eco.Shared.Serialization;
    using System;
    using System.Collections.Generic;

    ///<summary>WorldObject that uses <see cref="PictureFrameComponent"/> to display images in the world.</summary>
    //This partial Holds interaction logic.
    [RequireComponent(typeof(PictureFrameComponent))]
    public partial class PictureFrameObject : WorldObject, IRepresentsItem
    {
        public override InteractResult OnActRight(InteractionContext context)
        {
            if (context.SelectedItem is not PictureItem picture) return InteractResult.Failure(Localizer.DoStr("Frame only accepts pictures."));

            var comp = this.GetComponent<PictureFrameComponent>();

            if (!comp.PictureSlot.IsEmpty)                       return InteractResult.Failure(Localizer.DoStr("Frame is already displaying an image."));

            if (comp.PictureSlot.TryAddItem(picture))
            {
                //If picture was added to the frame, remove it from the inventory
                context.SelectedStack.ModifyStack(context.Player.User, -1);
                return InteractResult.Success;
            }

            return InteractResult.NoOp;
        }
    }
}
