// 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 final_annotationTypeObjectSupport.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.3.0).
 */

#include "final_annotationTypeObjectSupport.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 "final_annotation.hpp"


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

// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_final_ann_valid_struct_type_identifier(
        TypeIdentifierPair& type_ids_final_ann_valid_struct)
{

    ReturnCode_t return_code_final_ann_valid_struct {eprosima::fastdds::dds::RETCODE_OK};
    return_code_final_ann_valid_struct =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "final_ann_valid_struct", type_ids_final_ann_valid_struct);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_final_ann_valid_struct)
    {
        StructTypeFlag struct_flags_final_ann_valid_struct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::FINAL,
                false, false);
        QualifiedTypeName type_name_final_ann_valid_struct = "final_ann_valid_struct";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_final_ann_valid_struct;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_final_ann_valid_struct;
        AppliedAnnotationSeq tmp_ann_custom_final_ann_valid_struct;
        eprosima::fastcdr::optional<AppliedVerbatimAnnotation> verbatim_final_ann_valid_struct;
        if (!tmp_ann_custom_final_ann_valid_struct.empty())
        {
            ann_custom_final_ann_valid_struct = tmp_ann_custom_final_ann_valid_struct;
        }

        CompleteTypeDetail detail_final_ann_valid_struct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_final_ann_valid_struct, ann_custom_final_ann_valid_struct, type_name_final_ann_valid_struct.to_string());
        CompleteStructHeader header_final_ann_valid_struct;
        header_final_ann_valid_struct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_final_ann_valid_struct);
        CompleteStructMemberSeq member_seq_final_ann_valid_struct;
        {
            TypeIdentifierPair type_ids_first;
            ReturnCode_t return_code_first {eprosima::fastdds::dds::RETCODE_OK};
            return_code_first =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_int32_t", type_ids_first);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_first)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "first Structure member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            StructMemberFlag member_flags_first = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_first = 0x00000000;
            bool common_first_ec {false};
            CommonStructMember common_first {TypeObjectUtils::build_common_struct_member(member_id_first, member_flags_first, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_first, common_first_ec))};
            if (!common_first_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure first member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_first = "first";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_first;
            ann_custom_final_ann_valid_struct.reset();
            CompleteMemberDetail detail_first = TypeObjectUtils::build_complete_member_detail(name_first, member_ann_builtin_first, ann_custom_final_ann_valid_struct);
            CompleteStructMember member_first = TypeObjectUtils::build_complete_struct_member(common_first, detail_first);
            TypeObjectUtils::add_complete_struct_member(member_seq_final_ann_valid_struct, member_first);
        }
        CompleteStructType struct_type_final_ann_valid_struct = TypeObjectUtils::build_complete_struct_type(struct_flags_final_ann_valid_struct, header_final_ann_valid_struct, member_seq_final_ann_valid_struct);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_final_ann_valid_struct, type_name_final_ann_valid_struct.to_string(), type_ids_final_ann_valid_struct))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "final_ann_valid_struct already registered in TypeObjectRegistry for a different type.");
        }
    }
}// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_final_ann_extra_parameter_struct_type_identifier(
        TypeIdentifierPair& type_ids_final_ann_extra_parameter_struct)
{

    ReturnCode_t return_code_final_ann_extra_parameter_struct {eprosima::fastdds::dds::RETCODE_OK};
    return_code_final_ann_extra_parameter_struct =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "final_ann_extra_parameter_struct", type_ids_final_ann_extra_parameter_struct);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_final_ann_extra_parameter_struct)
    {
        StructTypeFlag struct_flags_final_ann_extra_parameter_struct = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::FINAL,
                false, false);
        QualifiedTypeName type_name_final_ann_extra_parameter_struct = "final_ann_extra_parameter_struct";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_final_ann_extra_parameter_struct;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_final_ann_extra_parameter_struct;
        AppliedAnnotationSeq tmp_ann_custom_final_ann_extra_parameter_struct;
        eprosima::fastcdr::optional<AppliedVerbatimAnnotation> verbatim_final_ann_extra_parameter_struct;
        if (!tmp_ann_custom_final_ann_extra_parameter_struct.empty())
        {
            ann_custom_final_ann_extra_parameter_struct = tmp_ann_custom_final_ann_extra_parameter_struct;
        }

        CompleteTypeDetail detail_final_ann_extra_parameter_struct = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_final_ann_extra_parameter_struct, ann_custom_final_ann_extra_parameter_struct, type_name_final_ann_extra_parameter_struct.to_string());
        CompleteStructHeader header_final_ann_extra_parameter_struct;
        header_final_ann_extra_parameter_struct = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_final_ann_extra_parameter_struct);
        CompleteStructMemberSeq member_seq_final_ann_extra_parameter_struct;
        {
            TypeIdentifierPair type_ids_first;
            ReturnCode_t return_code_first {eprosima::fastdds::dds::RETCODE_OK};
            return_code_first =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_int32_t", type_ids_first);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_first)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "first Structure member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            StructMemberFlag member_flags_first = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_first = 0x00000000;
            bool common_first_ec {false};
            CommonStructMember common_first {TypeObjectUtils::build_common_struct_member(member_id_first, member_flags_first, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_first, common_first_ec))};
            if (!common_first_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure first member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_first = "first";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_first;
            ann_custom_final_ann_extra_parameter_struct.reset();
            CompleteMemberDetail detail_first = TypeObjectUtils::build_complete_member_detail(name_first, member_ann_builtin_first, ann_custom_final_ann_extra_parameter_struct);
            CompleteStructMember member_first = TypeObjectUtils::build_complete_struct_member(common_first, detail_first);
            TypeObjectUtils::add_complete_struct_member(member_seq_final_ann_extra_parameter_struct, member_first);
        }
        CompleteStructType struct_type_final_ann_extra_parameter_struct = TypeObjectUtils::build_complete_struct_type(struct_flags_final_ann_extra_parameter_struct, header_final_ann_extra_parameter_struct, member_seq_final_ann_extra_parameter_struct);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_final_ann_extra_parameter_struct, type_name_final_ann_extra_parameter_struct.to_string(), type_ids_final_ann_extra_parameter_struct))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "final_ann_extra_parameter_struct already registered in TypeObjectRegistry for a different type.");
        }
    }
}// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_final_ann_on_struct_member_type_identifier(
        TypeIdentifierPair& type_ids_final_ann_on_struct_member)
{

    ReturnCode_t return_code_final_ann_on_struct_member {eprosima::fastdds::dds::RETCODE_OK};
    return_code_final_ann_on_struct_member =
        eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
        "final_ann_on_struct_member", type_ids_final_ann_on_struct_member);
    if (eprosima::fastdds::dds::RETCODE_OK != return_code_final_ann_on_struct_member)
    {
        StructTypeFlag struct_flags_final_ann_on_struct_member = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
                false, false);
        QualifiedTypeName type_name_final_ann_on_struct_member = "final_ann_on_struct_member";
        eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_final_ann_on_struct_member;
        eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_final_ann_on_struct_member;
        CompleteTypeDetail detail_final_ann_on_struct_member = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_final_ann_on_struct_member, ann_custom_final_ann_on_struct_member, type_name_final_ann_on_struct_member.to_string());
        CompleteStructHeader header_final_ann_on_struct_member;
        header_final_ann_on_struct_member = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_final_ann_on_struct_member);
        CompleteStructMemberSeq member_seq_final_ann_on_struct_member;
        {
            TypeIdentifierPair type_ids_first;
            ReturnCode_t return_code_first {eprosima::fastdds::dds::RETCODE_OK};
            return_code_first =
                eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
                "_int32_t", type_ids_first);

            if (eprosima::fastdds::dds::RETCODE_OK != return_code_first)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                        "first Structure member TypeIdentifier unknown to TypeObjectRegistry.");
                return;
            }
            StructMemberFlag member_flags_first = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
                    false, false, false, false);
            MemberId member_id_first = 0x00000000;
            bool common_first_ec {false};
            CommonStructMember common_first {TypeObjectUtils::build_common_struct_member(member_id_first, member_flags_first, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_first, common_first_ec))};
            if (!common_first_ec)
            {
                EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure first member TypeIdentifier inconsistent.");
                return;
            }
            MemberName name_first = "first";
            eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_first;
            ann_custom_final_ann_on_struct_member.reset();
            AppliedAnnotationSeq tmp_ann_custom_first;
            eprosima::fastcdr::optional<std::string> unit_first;
            eprosima::fastcdr::optional<AnnotationParameterValue> min_first;
            eprosima::fastcdr::optional<AnnotationParameterValue> max_first;
            eprosima::fastcdr::optional<std::string> hash_id_first;
            if (unit_first.has_value() || min_first.has_value() || max_first.has_value() || hash_id_first.has_value())
            {
                member_ann_builtin_first = TypeObjectUtils::build_applied_builtin_member_annotations(unit_first, min_first, max_first, hash_id_first);
            }
            if (!tmp_ann_custom_first.empty())
            {
                ann_custom_final_ann_on_struct_member = tmp_ann_custom_first;
            }
            CompleteMemberDetail detail_first = TypeObjectUtils::build_complete_member_detail(name_first, member_ann_builtin_first, ann_custom_final_ann_on_struct_member);
            CompleteStructMember member_first = TypeObjectUtils::build_complete_struct_member(common_first, detail_first);
            TypeObjectUtils::add_complete_struct_member(member_seq_final_ann_on_struct_member, member_first);
        }
        CompleteStructType struct_type_final_ann_on_struct_member = TypeObjectUtils::build_complete_struct_type(struct_flags_final_ann_on_struct_member, header_final_ann_on_struct_member, member_seq_final_ann_on_struct_member);
        if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
                TypeObjectUtils::build_and_register_struct_type_object(struct_type_final_ann_on_struct_member, type_name_final_ann_on_struct_member.to_string(), type_ids_final_ann_on_struct_member))
        {
            EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
                    "final_ann_on_struct_member already registered in TypeObjectRegistry for a different type.");
        }
    }
}
