using System;
using BO.AppServer.Metadata.Dto;
using BO.Console.Commands.Base;
using Quadarax.Foundation.Core.QConsole;
using Quadarax.Foundation.Core.QConsole.Attributes;

namespace BO.Console.Commands.User
{
    [CommandDefinition]
    internal class UserAddCommand : AbstractPostCommand<UserCDto, UserRDto>
    {
        #region *** Constants ***
        private const string CS_CMD_USERADD_NAME = "user_add";
        private const string CS_CMD_USERADD_DESCR = "Add new user/s by import file.";
        #endregion

        #region *** Properties ***

        public override string Name => CS_CMD_USERADD_NAME;
        public override string Description => CS_CMD_USERADD_DESCR;

        #endregion

        #region *** Constructor ***
        public UserAddCommand(Engine engine) : base(engine)
        {
        }
        #endregion

        #region *** EXECUTE ***
        protected override  UserRDto IterationExecute(UserCDto data)
        {
            WriteDebugInfo($"User '{data.Name}' starts creating...");
            var result = Client.CreateUserAsync(data).Result;
            WriteCaption($"User '{data.Name}' created.");
            return result;
        }

        #endregion

        #region *** Private operations ***
        #endregion
    }
}
