﻿// MIT License. Copyright (c) 2016 Maxim Kuzmin. Contacts: https://github.com/maxim-kuzmin

// Author: Maxim Kuzmin

using Makc2017.Core.Execution.Operations.Async;
using Makc2017.Core.Resources.Errors;
using Makc2017.Modules.User.Filters;
using Makc2017.Modules.User.Models;
using System;
using System.Threading.Tasks;

namespace Makc2017.Modules.User.Operations.Item
{
    /// <summary>
    /// Модули. Модуль "User". Операции. Операция, выполняющая функцию получения элемента.
    /// </summary>
    public class ModuleUserOperationItemGet : CoreExecutionOperationAsyncWithInputAndOutputData
        <
            ModuleUserFilterItem,
            ModuleUserModelItem
        >
    {
        #region Constructors

        /// <summary>
        /// Конструктор.
        /// </summary>
        /// <param name="executableFunction">Выполняемая функция.</param>
        /// <param name="coreResourceErrors">Ресурсы ошибок ядра.</param>
        public ModuleUserOperationItemGet(
            Func<ModuleUserFilterItem, Task<ModuleUserModelItem>> executableFunction,
            CoreResourceErrors coreResourceErrors
            ) : base(
                executableFunction,
                null,
                TransformInputData,
                null,
                null,
                coreResourceErrors
                )
        {
        }

        #endregion Constructors

        #region Internal methods

        internal static ModuleUserFilterItem TransformInputData(ModuleUserFilterItem inputData)
        {
            if (inputData == null)
            {
                inputData = new ModuleUserFilterItem();
            }

            inputData.Normalize();

            return inputData;
        }

        #endregion Internal methods
    }
}