using RobotNet.MapShares.Dtos;

namespace RobotNet.WebApp.Robots.Components.Monitoring.Element;

public class ElementModel(ElementDto element, NodeModel node) : IDisposable
{
    public Guid Id => Element.Id;
    public Guid ModelId => Element.ModelId;
    public Guid NodeId => Element.NodeId;
    public Guid MapId => Element.MapId;
    public string Name => Element.Name;
    public double X => Node.X;
    public double Y => Node.Y;
    public double Theta => Node.Theta;
    public double OffsetX => Element.OffsetX;
    public double OffsetY => Element.OffsetY;
    public bool IsOpen => Element.IsOpen;
    public string Content => Element.Content;

    public ElementDto Element { get; private set; } = element;
    public NodeModel Node { get; private set; } = node;

    public event Func<Task>? UpdateChanged;

    public void Update(ElementDto element)
    {
        Element.IsOpen = element.IsOpen;
        Element.OffsetX = element.OffsetX;
        Element.OffsetY = element.OffsetY;
        Element.Content = element.Content;
        UpdateChanged?.Invoke();
    }

    public void Dispose()
    {
        GC.SuppressFinalize(this);
    }
}
