{%- macro print_value(type, value) -%}
  {{ "\"" if type == "string"}}{{value}}{{ "\"" if type == "string"}}
{%- endmacro %}

{%- macro format_remarks(text) -%}
{%- set notes = '\n        /// '.join(text.splitlines()).encode('ascii', 'xmlcharrefreplace').decode() -%}
{{notes}}
{%- endmacro -%}

{%- macro format_xml_doc(text) -%}
{%- set escaped = text.encode('ascii', 'xmlcharrefreplace').decode() -%}
  {%- if not escaped.endswith('.')-%}
    {{escaped + '.'}}
  {%- else -%}
    {{escaped}}
  {%- endif -%}
{%- endmacro -%}

// <copyright file="{{class}}.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// 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.
// </copyright>

// <auto-generated> This file has been auto generated from buildscripts/semantic-conventions{{template}}</auto-generated>

using System;

namespace {{pkg | trim}}
{
    /// <summary>
    /// Constants for semantic attribute names outlined by the OpenTelemetry specifications.
    {% if class == "TraceSemanticConventions" %}
    /// <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/README.md"/>.
    {% elif class == "ResourceSemanticConventions" %}
    /// <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md"/>.
    {% endif %}
    /// </summary>
    /// <remarks>
    /// Schema and specification version: {{schemaUrl}}.
    /// </remarks>
    public static class {{class}}
    {
{% if class == "TraceSemanticConventions" %}
        /// <summary>
        /// Attribute for db.instance.
        /// </summary>
        public const string AttributeDbInstance = "db.instance";

{% endif %}
{% for attribute in attributes if attribute.is_local and not attribute.ref %}
  {% if not loop.first %}{{"\n"}}{% endif %}
        /// <summary>
        /// {{format_xml_doc(attribute.brief | render_markdown(code="<c>{0}</c>", paragraph="{0}"))}}
        /// </summary>
  {% if attribute.note %}
        /// <remarks>
        /// {{format_remarks(attribute.note | to_doc_brief | escape | render_markdown(code="<c>{0}</c>", paragraph="{0}"))}}.
        /// </remarks>
  {% endif %}
  {% if attribute.deprecated %}
        [Obsolete("{{attribute.deprecated | to_doc_brief}}")]
  {% endif %}
        public const string Attribute{{attribute.fqn  | replace("-","_") | to_camelcase(True)}} = "{{attribute.fqn}}";
{% endfor %}
{% for semconv in semconvs.values() | unique(attribute="prefix") %}
  {% if semconv.prefix %}

        /// <summary>
        /// Prefix for '{{semconv.semconv_id}}'.
        /// </summary>
        public static readonly string Prefix{{semconv.semconv_id | replace("-","_") | to_camelcase(True)}} = "{{semconv.prefix}}";
  {% endif %}
{% endfor %}
{% for semconv in semconvs.values() %}
  {% if semconv.GROUP_TYPE_NAME == 'event' %}

        /// <summary>
        /// Event name for '{{semconv.semconv_id}}'.
        /// </summary>
        public static readonly string Event{{semconv.semconv_id | replace("-","_") | to_camelcase(True)}} = "{{semconv.name}}";
  {% endif %}
{% endfor %}
{% for attribute in attributes if attribute.is_local and not attribute.ref %}
  {% if attribute.is_enum %}
  {% set class_name = attribute.fqn | to_camelcase(True) ~ "Values" %}
  {% set type = attribute.attr_type.enum_type %}

        /// <summary>
        /// {{format_xml_doc(attribute.brief | render_markdown(code="<c>{0}</c>", paragraph="{0}"))}}
        /// </summary>
        public static class {{class_name}}
        {
            {% for member in attribute.attr_type.members %}
            /// <summary>
            /// {{format_xml_doc(member.brief | render_markdown(code="<c>{0}</c>", paragraph="{0}"))}}
            /// </summary>
            public const {{ type }} {{ member.member_id | to_camelcase(True) }} = {{ print_value(type, member.value) }};
            {% if not loop.last %}{{"\n"}}{% endif %}
            {% endfor %}
        }
  {% endif %}
{% endfor %}
    }
}

