using System;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using CommonHelpers; // H…-types from DotNetHelpers library (with some DB-support + simple “ORM”)
using MyFlat.Base; // common types for MyFlat application (base exceptions etc.)

namespace MyFlat.DB {

//**************************************************************************************************
/// <summary>
/// Financial month info obtainment (current fin.term), via stored procedure call
/// </summary>
public static class GetFinTermInfo_SP {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public const string Name = "ЛК::Информация по текущему ФП"; // current financial term info
/*
public static readonly Guid
   //Status_ = SPCommonStatuses.,
   //Status_ = new Guid( "" ),
*/
public static HSPCommandResultOut<FinTermInfo_Output>
   InvalidResult => new HSPCommandResultOut<FinTermInfo_Output>();
//==================================================================================================

public static async Task<HSPCommandResultOut<FinTermInfo_Output>> EXEC_A()
{
   using (new HSP(Name))
   {
      await HSP.Connect_A();
      var p = new TParameters();
      var ( rp, cmd ) = HSP.PrepareCommand( p.ID, p.NO, p.Name, p.Year, p.MonthNO );
      HSP.SetParametersDescriptor( p );
      await HSPCommandDispose.ExecuteNonQuery_A( cmd );
      var output = HSP.Success( rp ) ? new FinTermInfo_Output() : null;
      return new HSPCommandResultOut<FinTermInfo_Output>( rp, output );
   }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
internal class TParameters
{
   public readonly SqlParameter
      ID = HSqlParam.Out( "ИД", SqlDbType.UniqueIdentifier ),
      NO = HSqlParam.Out( "Номер", SqlDbType.Int ),
      Name = HSqlParam.Out( "Название", SqlDbType.NVarChar, -1 ),
                            //DBConstants.ShortNameCapacity ),
      Year = HSqlParam.Out( "Год", SqlDbType.Int ),
      MonthNO = HSqlParam.Out( "Месяц", SqlDbType.Int );
} // TParameters
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // GetFinTermInfo_SP
//**************************************************************************************************

/// <summary>
/// Output values model (as united chunk)
/// </summary>
public class FinTermInfo_Output: SPOutputBase
{
   public Guid ID = GUID( P.ID ); // financial month identifier
   public int NO = INT( P.NO ); // fin.term absolute number in history
   public string Name = NS( P.Name ); // fin.term name (title)
   public int Year = INT( P.Year ); // year of financial month
   public int MonthNO = INT( P.MonthNO ); // financial month number in year
   static GetFinTermInfo_SP.TParameters P =>
      (GetFinTermInfo_SP.TParameters)HSP.ParametersDescriptor;
} // FinTermInfo_Output

//--------------------------------------------------------------------------------------------------
} // MyFlat.DB
