using System.Data;
using System.Xml;
using System.Xml.Linq;

namespace e_suite.Database.Migrator.SqlWrapper;

public interface ISqlWrapper : IDisposable
{
    /// <summary>
    /// Name of the stored procedure to call.
    /// Note: can use either CommandName or the CommandText, but not both at the same time.
    /// </summary>
    string CommandName { get; set; }

    /// <summary>
    /// Adhoc SQL text.
    /// Note: can use either CommandName or the CommandText, but not both at the same time.
    /// </summary>
    string CommandText { get; set; }

    void AddParameter(string name, SqlDbType type, object value);

    /// <summary>
    /// Adds a new parameter to the stored procedure
    /// </summary>
    /// <param name="name">name of the parameter. For example @test   the @ symbol is optional</param>
    /// <param name="type">database type of the parameter</param>
    /// <param name="direction">Specifies if this is an input or output parameter</param>
    /// <param name="value">actual value for the parameter</param>
    void AddParameter(string name, SqlDbType type, ParameterDirection direction, object value);

    /// <summary>
    /// Retrieves the current value of a parameter
    /// </summary>
    /// <param name="name">name of the parameter that you need the value for</param>
    /// <returns>either the value of the named parameter, or null if it does not exist</returns>
    object? GetParamValue(string name);

    /// <summary>
    /// Removes all parameters from the internal parameter list.
    /// </summary>
    void Clear();


    /// <summary>
    /// Execute the stored procedure without the expectation of any result sets being returned.
    /// note: output parameters will be set when the method completes.
    /// </summary>
    void Execute();

    /// <summary>
    /// Retrieves the procedures return value
    /// </summary>
    /// <returns>the return value from the procedure call</returns>
    object? GetReturnValue();

    /// <summary>
    /// Execute stored procedure with return an XML reader.
    /// </summary>
    /// <returns></returns>
    XmlReader ExecuteXmlReader();

    /// <summary>
    /// Execute the stored procedure with the result returned as an XmlDocument
    /// </summary>
    /// <returns>XML document containing the result of the stored procedure call</returns>
    XmlDocument ExecuteXmlDocument();

    /// <summary>
    /// Execute the stored procedure with the result returned as an XDcoument
    /// </summary>
    /// <returns></returns>
    XDocument ExecuteXDocument();

    IDataReader ExecuteReader();


    bool IsDisposed { get; }
    int ParamCount { get; }

    /// <summary>
    /// Timeout for sql commands.  Default is 30 seconds. 0 means no limit.
    /// </summary>
    int Timeout { get; set; }
}