// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file extra_unionsTypeObjectSupport.cxx
 * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file
 *
 * This file was generated by the tool fastddsgen (version: 4.1.0).
 */

#include "extra_unionsTypeObjectSupport.hpp"

#include <mutex>
#include <string>

#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/xtypes/common.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>
#include "extra_unions.hpp"


using namespace eprosima::fastdds::dds::xtypes;

namespace MyModule {
void register_ScopedEnumHelper_type_identifier(
        TypeIdentifierPair& type_ids_ScopedEnumHelper)
{
    ReturnCode_t return_code_ScopedEnumHelper {eprosima::fastdds::dds::RETCODE_OK};
    return_code_ScopedEnumHelper =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "MyModule::ScopedEnumHelper", type_ids_ScopedEnumHelper);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_ScopedEnumHelper)
    {
        EnumTypeFlag enum_flags_ScopedEnumHelper = 0;
        BitBound bit_bound_ScopedEnumHelper = 32;
        CommonEnumeratedHeader common_ScopedEnumHelper = TypeObjectUtils::build_common_enumerated_header(bit_bound_ScopedEnumHelper);
        QualifiedTypeName type_name_ScopedEnumHelper = "MyModule::ScopedEnumHelper";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_ScopedEnumHelper;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_ScopedEnumHelper;
        CompleteTypeDetail detail_ScopedEnumHelper = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ScopedEnumHelper, ann_custom_ScopedEnumHelper, type_name_ScopedEnumHelper.to_string());
        CompleteEnumeratedHeader header_ScopedEnumHelper = TypeObjectUtils::build_complete_enumerated_header(common_ScopedEnumHelper, detail_ScopedEnumHelper);
        CompleteEnumeratedLiteralSeq literal_seq_ScopedEnumHelper;
        {
            EnumeratedLiteralFlag flags_ENUM_VALUE_1 = TypeObjectUtils::build_enumerated_literal_flag(false);
            CommonEnumeratedLiteral common_ENUM_VALUE_1 = TypeObjectUtils::build_common_enumerated_literal(0, flags_ENUM_VALUE_1);
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE_1;
            ann_custom_ScopedEnumHelper.reset();
            MemberName name_ENUM_VALUE_1 = "ENUM_VALUE_1";
            CompleteMemberDetail detail_ENUM_VALUE_1 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE_1, member_ann_builtin_ENUM_VALUE_1, ann_custom_ScopedEnumHelper);
            CompleteEnumeratedLiteral literal_ENUM_VALUE_1 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE_1, detail_ENUM_VALUE_1);
            TypeObjectUtils::add_complete_enumerated_literal(literal_seq_ScopedEnumHelper, literal_ENUM_VALUE_1);
        }
        {
            EnumeratedLiteralFlag flags_ENUM_VALUE_2 = TypeObjectUtils::build_enumerated_literal_flag(false);
            CommonEnumeratedLiteral common_ENUM_VALUE_2 = TypeObjectUtils::build_common_enumerated_literal(1, flags_ENUM_VALUE_2);
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE_2;
            ann_custom_ScopedEnumHelper.reset();
            MemberName name_ENUM_VALUE_2 = "ENUM_VALUE_2";
            CompleteMemberDetail detail_ENUM_VALUE_2 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE_2, member_ann_builtin_ENUM_VALUE_2, ann_custom_ScopedEnumHelper);
            CompleteEnumeratedLiteral literal_ENUM_VALUE_2 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE_2, detail_ENUM_VALUE_2);
            TypeObjectUtils::add_complete_enumerated_literal(literal_seq_ScopedEnumHelper, literal_ENUM_VALUE_2);
        }
        {
            EnumeratedLiteralFlag flags_ENUM_VALUE_3 = TypeObjectUtils::build_enumerated_literal_flag(false);
            CommonEnumeratedLiteral common_ENUM_VALUE_3 = TypeObjectUtils::build_common_enumerated_literal(2, flags_ENUM_VALUE_3);
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE_3;
            ann_custom_ScopedEnumHelper.reset();
            MemberName name_ENUM_VALUE_3 = "ENUM_VALUE_3";
            CompleteMemberDetail detail_ENUM_VALUE_3 = TypeObjectUtils::build_complete_member_detail(name_ENUM_VALUE_3, member_ann_builtin_ENUM_VALUE_3, ann_custom_ScopedEnumHelper);
            CompleteEnumeratedLiteral literal_ENUM_VALUE_3 = TypeObjectUtils::build_complete_enumerated_literal(common_ENUM_VALUE_3, detail_ENUM_VALUE_3);
            TypeObjectUtils::add_complete_enumerated_literal(literal_seq_ScopedEnumHelper, literal_ENUM_VALUE_3);
        }
        CompleteEnumeratedType enumerated_type_ScopedEnumHelper = TypeObjectUtils::build_complete_enumerated_type(enum_flags_ScopedEnumHelper, header_ScopedEnumHelper,
                literal_seq_ScopedEnumHelper);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_enumerated_type_object(enumerated_type_ScopedEnumHelper, type_name_ScopedEnumHelper.to_string(), type_ids_ScopedEnumHelper))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                "MyModule::ScopedEnumHelper already registered in TypeObjectRegistry for a different type.");
        }
    }
}
} // namespace MyModule
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_UnionScopedDiscriminator_type_identifier(
        TypeIdentifierPair& type_ids_UnionScopedDiscriminator)
{
    ReturnCode_t return_code_UnionScopedDiscriminator {eprosima::fastdds::dds::RETCODE_OK};
    return_code_UnionScopedDiscriminator =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "UnionScopedDiscriminator", type_ids_UnionScopedDiscriminator);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_UnionScopedDiscriminator)
    {
        UnionTypeFlag union_flags_UnionScopedDiscriminator = TypeObjectUtils::build_union_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_UnionScopedDiscriminator = "UnionScopedDiscriminator";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_UnionScopedDiscriminator;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_UnionScopedDiscriminator;
        CompleteTypeDetail detail_UnionScopedDiscriminator = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_UnionScopedDiscriminator, ann_custom_UnionScopedDiscriminator, type_name_UnionScopedDiscriminator.to_string());
        CompleteUnionHeader header_UnionScopedDiscriminator = TypeObjectUtils::build_complete_union_header(detail_UnionScopedDiscriminator);
        UnionDiscriminatorFlag member_flags_UnionScopedDiscriminator = TypeObjectUtils::build_union_discriminator_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                false);
        return_code_UnionScopedDiscriminator =
            eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
            "MyModule::ScopedEnumHelper", type_ids_UnionScopedDiscriminator);

        if (return_code_UnionScopedDiscriminator != eprosima::fastdds::dds::RETCODE_OK)
        {
            ::MyModule::register_ScopedEnumHelper_type_identifier(type_ids_UnionScopedDiscriminator);
        }
        CommonDiscriminatorMember common_UnionScopedDiscriminator;
        if (EK_COMPLETE == type_ids_UnionScopedDiscriminator.type_identifier1()._d() || TK_NONE == type_ids_UnionScopedDiscriminator.type_identifier2()._d())
        {
            common_UnionScopedDiscriminator = TypeObjectUtils::build_common_discriminator_member(member_flags_UnionScopedDiscriminator, type_ids_UnionScopedDiscriminator.type_identifier1());
        }
        else if (EK_COMPLETE == type_ids_UnionScopedDiscriminator.type_identifier2()._d())
        {
            common_UnionScopedDiscriminator = TypeObjectUtils::build_common_discriminator_member(member_flags_UnionScopedDiscriminator, type_ids_UnionScopedDiscriminator.type_identifier2());
        }
        else
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "UnionScopedDiscriminator discriminator TypeIdentifier inconsistent.");
            return;
        }
        type_ann_builtin_UnionScopedDiscriminator.reset();
        ann_custom_UnionScopedDiscriminator.reset();
        CompleteDiscriminatorMember discriminator_UnionScopedDiscriminator = TypeObjectUtils::build_complete_discriminator_member(common_UnionScopedDiscriminator,
                type_ann_builtin_UnionScopedDiscriminator, ann_custom_UnionScopedDiscriminator);
        CompleteUnionMemberSeq member_seq_UnionScopedDiscriminator;
        {
            return_code_UnionScopedDiscriminator =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_int32_t", type_ids_UnionScopedDiscriminator);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_UnionScopedDiscriminator)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "first Union member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            UnionMemberFlag member_flags_first = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false);
            UnionCaseLabelSeq label_seq_first;
            TypeObjectUtils::add_union_case_label(label_seq_first, static_cast<int32_t>(MyModule::ScopedEnumHelper::ENUM_VALUE_1));
            MemberId member_id_first = 0x00000001;
            bool common_first_ec {false};
            CommonUnionMember common_first {TypeObjectUtils::build_common_union_member(member_id_first,
                    member_flags_first, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_UnionScopedDiscriminator,
                        common_first_ec), label_seq_first)};
            if (!common_first_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union first member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_first = "first";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_first;
            ann_custom_UnionScopedDiscriminator.reset();
            CompleteMemberDetail detail_first = TypeObjectUtils::build_complete_member_detail(name_first, member_ann_builtin_first, ann_custom_UnionScopedDiscriminator);
            CompleteUnionMember member_first = TypeObjectUtils::build_complete_union_member(common_first, detail_first);
            TypeObjectUtils::add_complete_union_member(member_seq_UnionScopedDiscriminator, member_first);
        }
        {
            return_code_UnionScopedDiscriminator =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_int64_t", type_ids_UnionScopedDiscriminator);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_UnionScopedDiscriminator)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "second Union member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            UnionMemberFlag member_flags_second = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false);
            UnionCaseLabelSeq label_seq_second;
            TypeObjectUtils::add_union_case_label(label_seq_second, static_cast<int32_t>(MyModule::ScopedEnumHelper::ENUM_VALUE_2));
            MemberId member_id_second = 0x00000002;
            bool common_second_ec {false};
            CommonUnionMember common_second {TypeObjectUtils::build_common_union_member(member_id_second,
                    member_flags_second, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_UnionScopedDiscriminator,
                        common_second_ec), label_seq_second)};
            if (!common_second_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union second member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_second = "second";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_second;
            ann_custom_UnionScopedDiscriminator.reset();
            CompleteMemberDetail detail_second = TypeObjectUtils::build_complete_member_detail(name_second, member_ann_builtin_second, ann_custom_UnionScopedDiscriminator);
            CompleteUnionMember member_second = TypeObjectUtils::build_complete_union_member(common_second, detail_second);
            TypeObjectUtils::add_complete_union_member(member_seq_UnionScopedDiscriminator, member_second);
        }
        {
            return_code_UnionScopedDiscriminator =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_byte", type_ids_UnionScopedDiscriminator);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_UnionScopedDiscriminator)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "third Union member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            UnionMemberFlag member_flags_third = TypeObjectUtils::build_union_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    true, false);
            UnionCaseLabelSeq label_seq_third;
            MemberId member_id_third = 0x00000003;
            bool common_third_ec {false};
            CommonUnionMember common_third {TypeObjectUtils::build_common_union_member(member_id_third,
                    member_flags_third, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_UnionScopedDiscriminator,
                        common_third_ec), label_seq_third)};
            if (!common_third_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Union third member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_third = "third";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_third;
            ann_custom_UnionScopedDiscriminator.reset();
            CompleteMemberDetail detail_third = TypeObjectUtils::build_complete_member_detail(name_third, member_ann_builtin_third, ann_custom_UnionScopedDiscriminator);
            CompleteUnionMember member_third = TypeObjectUtils::build_complete_union_member(common_third, detail_third);
            TypeObjectUtils::add_complete_union_member(member_seq_UnionScopedDiscriminator, member_third);
        }
        CompleteUnionType union_type_UnionScopedDiscriminator = TypeObjectUtils::build_complete_union_type(union_flags_UnionScopedDiscriminator, header_UnionScopedDiscriminator, discriminator_UnionScopedDiscriminator,
                member_seq_UnionScopedDiscriminator);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_union_type_object(union_type_UnionScopedDiscriminator, type_name_UnionScopedDiscriminator.to_string(), type_ids_UnionScopedDiscriminator))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "UnionScopedDiscriminator already registered in TypeObjectRegistry for a different type.");
        }
    }
}
