using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.FourEngine.Resources;

namespace MonoGame.FourEngine.Raycast
{
    public class RaycastObject : Entity, IRaycastObject
    {
        public Vector2 Position { get; set; }
        public float VerticalPosition { get; set; }
        public virtual Sprite Sprite { get; }
        public virtual Point Frame { get; protected set; }

        protected virtual SpriteDefinition SpriteDefinition { get; }

        public RaycastObject()
        {
            if (SpriteDefinition != null)
            {
                ServiceLocator.ResourceManager.Add(ResourceTypes.Sprite, SpriteDefinition);
                if (!string.IsNullOrEmpty(SpriteDefinition?.FileName))
                    Sprite = ServiceLocator.ResourceManager.Get<Sprite>(SpriteDefinition.FileName);
            }
        }

        public virtual void Draw(SpriteBatch batch, Rectangle destinationRectangle, Rectangle sourceRectangle, Color color)
        {
            batch.Draw(
                Sprite.Texture,
                destinationRectangle,
                sourceRectangle,
                color);
        }

        public virtual void UpdateFrameByCamera(IRaycastCamera camera)
        { }
    }
}