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

// Author: Maxim Kuzmin

using Makc2016.Core.Execution.Operations.Async;
using Makc2016.Modules.Role.Models;
using Makc2016.Modules.Role.Resources.Successes;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Makc2016.Modules.Role.Operations.Item
{
    /// <summary>
    /// Модули. Модуль "Role". Операции. Операция, выполняющая функцию обновления элемента.
    /// </summary>
    public class ModuleRoleOperationItemUpdate : CoreExecutionOperationAsyncWithInputAndOutputData
        <
            ModuleRoleModelItem,
            ModuleRoleModelItem
        >
    {
        #region Constructors

        /// <summary>
        /// Конструктор.
        /// </summary>
        /// <param name="executableFunction">Выполняемая функция.</param>
        public ModuleRoleOperationItemUpdate(
            Func<ModuleRoleModelItem, Task<ModuleRoleModelItem>> executableFunction
            ) : base(
                executableFunction,
                ModuleRoleOperationItemInsert.GetErrorMessages,
                null,
                GetSuccessMessages,
                null
                )
        {
        }

        #endregion Constructors

        #region Private methods

        private static IEnumerable<string> GetSuccessMessages(
            ModuleRoleModelItem inputData,
            ModuleRoleModelItem outputData
            )
        {
            return new[]
            {
                string.Format(
                    ModuleRoleResourceSuccesses.String_Format_Object_With_Id_Is_Updated,
                    outputData.ObjectRole.Id
                    )
            };
        }

        #endregion Private methods
    }
}