using System;
using System.Threading.Tasks;
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>
/// Flat services selection (via stored procedure call)
/// </summary>
public static class GetServiceList_SP {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public const string Name = "ЛК::Получение списка услуг"; // service list obtainment
/*
public static readonly Guid
   //Status_ = SPCommonStatuses.,
   //Status_ = new Guid( "" ),
*/
public static HSPResult<ServiceInfo_Item>
   InvalidResult => new HSPResult<ServiceInfo_Item>();
//==================================================================================================

public static Task<(HSPResult<ServiceInfo_Item>,string? Message)> EXEC_A() =>
   EXEC_A( false );

public static async Task<(HSPResult<ServiceInfo_Item>,string? Message)> EXEC_A(
   bool deviceAdmissibleOnly )
{
   using (new HSP(Name))
   {
      await HSP.Connect_A();
      var ( rp, cmd ) = HSP.PrepareCommand(
         HSqlParam.In( "СДопускомНаличияИПУ", deviceAdmissibleOnly ) );
         // with admission of consumption measurement device(s)
      var list = await HSP.DoReaderCommandVerify_A<ServiceInfo_Item>( rp, cmd );
      string? message = HSP.OutMessage( rp );
      if ( list.Count == 0 && message == null )
         throw HDBExceptionsSPAuto.InconsistentResult;
      return ( new HSPResult<ServiceInfo_Item>( rp, list ), message );
   }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // GetServiceList_SP
//**************************************************************************************************

/// <summary>
/// Result set (model)
/// </summary>
public class ServiceInfo_Item: ResultSetItemBase
{
   public Guid ID
      = GUID( "ИД" ); // ID
   public string Name
      = NS( "Название" ); // name
   public string TinyName
      = NS( "Краткое имя" ); // tiny name (very compact)
   public int NO
      = INT( "Номер" ); // NO (order number)
   public bool IsDevicePermissible
      = BOOL( "Допускает наличие ИПУ" );
      // is consumption measurement device admissible
   public ServiceInfo_Item ServiceInfo_Duplicate() =>
      (ServiceInfo_Item)MemberwiseClone();
} // ServiceInfo_Item

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