// This file was generated automatically by Qleany's generator, edit at your own risk! 
// If you do, be careful to not overwrite it when you run the generator again.
#pragma once

#include "{{ export_header }}"
#include "{{ feature_snake_name }}/{{ entity_mappable_with_snake }}_dto.h"
#include "{{ feature_snake_name }}/commands/create_{{ entity_mappable_with_snake }}_command.h"
#include "repository/interface_{{ entity_mappable_with_snake }}_repository.h"
#include <qleany/common/result.h>
#include <QPromise>

using namespace Qleany;
using namespace {{ application_cpp_domain_name }}::Entities;
using namespace {{ application_cpp_domain_name }}::Contracts::DTO::{{ feature_pascal_name }};
using namespace {{ application_cpp_domain_name }}::Contracts::Repository;
using namespace {{ application_cpp_domain_name }}::Contracts::CQRS::{{ feature_pascal_name }}::Commands;

namespace {{ application_cpp_domain_name }}::Application::Features::{{ feature_pascal_name }}::Commands
{
class {{ export }} Create{{ entity_mappable_with_pascal }}CommandHandler : public QObject
{
    Q_OBJECT
  public:
    Create{{ entity_mappable_with_pascal }}CommandHandler(Interface{{ entity_mappable_with_pascal }}Repository *repository);

    Result<{{ entity_mappable_with_pascal }}DTO> handle(QPromise<Result<void>> &progressPromise, const Create{{ entity_mappable_with_pascal }}Command &request);
    Result<{{ entity_mappable_with_pascal }}DTO> restore();

  Q_SIGNALS:
    void {{ entity_mappable_with_camel }}Created({{ application_cpp_domain_name }}::Contracts::DTO::{{ feature_pascal_name }}::{{ entity_mappable_with_pascal }}DTO {{ entity_mappable_with_camel }}Dto);
    void {{ entity_mappable_with_camel }}Removed(int id);
    {% if has_owner %}
    void relationWithOwnerInserted(int id, int ownerId, int position);
    void relationWithOwnerRemoved(int id, int ownerId);
    {% endif %}


  private:
    Interface{{ entity_mappable_with_pascal }}Repository *m_repository;
    Result<{{ entity_mappable_with_pascal }}DTO> handleImpl(QPromise<Result<void> >   & progressPromise, const Create{{ entity_mappable_with_pascal }}Command &request);
    Result<{{ entity_mappable_with_pascal }}DTO> restoreImpl();
    Result<{{ application_cpp_domain_name }}::Entities::{{ entity_mappable_with_pascal }}> m_newEntity;
    {% if has_owner %}
    int m_ownerId = -1;
    int m_position = -1;
        {% if owner_field_is_list %}
    QList<{{ application_cpp_domain_name }}::Entities::{{ entity_mappable_with_pascal }}> m_oldOwner{{ owner_field_name_pascal }};
    QList<{{ application_cpp_domain_name }}::Entities::{{ entity_mappable_with_pascal }}> m_owner{{ owner_field_name_pascal }}NewState;
        {% else %}
    {{ application_cpp_domain_name }}::Entities::{{ entity_mappable_with_pascal }} m_oldOwner{{ owner_field_name_pascal }};
    {{ application_cpp_domain_name }}::Entities::{{ entity_mappable_with_pascal }} m_owner{{ owner_field_name_pascal }}NewState;
       {% endif %}
    {% endif %}
    static bool s_mappingRegistered;
    void registerMappings();
    bool m_firstPass = true;
};

} // namespace {{ application_cpp_domain_name }}::Application::Features::{{ feature_pascal_name }}::Commands
