
using Godot;
using System.Collections.Generic;

namespace Rokojori
{  
  public interface CompositorEffectGraphTextureSlotInput
  {
    public RDTexture GetTexture();
    public CompositorEffectGraphProcessor GetProcessor();
    public void SetConnected( CompositorEffectGraphTextureSlot slot );
    public void ConnectTo( CompositorEffectGraphTextureSlot slot );
  }

  public class CompositorEffectGraphTextureSlot:CompositorEffectGraphConnection, CompositorEffectGraphTextureSlotInput
  {
    protected CompositorEffectGraphTextureSlotInput _input;
    public CompositorEffectGraphTextureSlotInput input => _input;

    public RDSampler sampler;

    RDTexture _texture;
    
    public RDTexture GetTexture()
    {
      return _texture;
    }

    public RDTexture ResolveTexture()
    {
      return _texture = _input.GetTexture();
    }

    public CompositorEffectGraphProcessor GetProcessor()
    {
      return _processor;
    }

    List<CompositorEffectGraphTextureSlot> _connectedSlots = new List<CompositorEffectGraphTextureSlot>();

    public void SetConnected( CompositorEffectGraphTextureSlot slot )
    {
      _connectedSlots.Add( slot );
    }

    public CompositorEffectGraphTextureSlot( CompositorEffectGraphProcessor processor ):base( processor )
    {

    }

    public void SetInput( CompositorEffectGraphTextureSlotInput input )
    {
      _input = input;
      input.SetConnected( this );
    }

    public void ConnectTo( CompositorEffectGraphTextureSlot slot )
    {
      slot.SetInput( this );
    }
  }
}