using System;

namespace InABox.Core
{
    public delegate void DigitalFormUpdateHandler(IDigitalFormDataModel model);

    public delegate void DigitalFormBeforeUpdateHandler(IDigitalFormDataModel model);

    public interface IDigitalFormDataModel
    {
        public Entity Entity { get; set; }
        
        IDigitalFormInstance Instance { get; set;  }

        public DigitalFormVariable[] Variables { get; set; }
        
        event DigitalFormUpdateHandler OnModelSaved;

        event DigitalFormBeforeUpdateHandler BeforeModelSaved;

        void Load(Action<IDigitalFormDataModel> callback);

        /// <summary>
        /// Saves the datamodel to the database, including the form instance and parent entity.
        /// </summary>
        /// <param name="callback">The callback to call once the update is finished, or <c>null</c> for synchronous execution.</param>
        void Update(Action<IDigitalFormDataModel>? callback);

        void DuplicateInstance();

        object? GetEntityValue(string name);
        void SetEntityValue(string name, object? value);
    }
}