// -*- mode: csharp -*-

/*
 * AUTOGENERATED BY glean_parser. DO NOT EDIT. DO NOT COMMIT.
 */
{# The rendered markdown is autogenerated, but this
Jinja2 template is not. Please file bugs! #}

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
{% macro obj_declaration(obj, suffix='', access='', lazy=False) %}
{{ access }} {% if lazy %} Lazy<{{ obj|type_name }}>{%- else %} {{ obj|type_name }}{% endif %} {{ obj.name|camelize }}{{ suffix }}
{%- if lazy %} = new Lazy<{{ obj|type_name }}>(() => {%- else %} = // generated from {{ obj.identifier() }}{% endif %}

            new {{ obj|type_name }}(
                {% for arg_name in extra_args if obj[arg_name] is defined %}
                {{ arg_name|camelize }}: {{ obj[arg_name]|csharp }}{{ "," if not loop.last }}
                {% endfor %}
            ){% if lazy %});{% else %};{% endif %}{% endmacro %}

using System;
using System.Collections.Generic;
using {{ glean_namespace }}.Private;

{# The C# metrics design require the class name to have a 'Definition'
suffix, in order to nicely call in the metrics from the consumer code.
The user code will be interested in the Value of the lazy instance, so
that's where the real class name should be used. #}
{% set metrics_class_name = category_name|Camelize + 'Definition' %}
namespace {{ namespace }}
{
    internal sealed class {{ metrics_class_name }}
    {
        private static readonly Lazy<{{ metrics_class_name }}>
          lazyInstance = new Lazy<{{ metrics_class_name }}>(() => new {{ metrics_class_name }}());
        public static {{ metrics_class_name }} {{ category_name|Camelize }} => lazyInstance.Value;

        // Private constructor to disallow instantiation from external callers.
        private {{ metrics_class_name }}() { }

#pragma warning disable IDE1006 // Naming Styles
    {% for obj in objs.values() %}
        {% if obj|attr("_generate_enums") %}
        {% for name, suffix in obj["_generate_enums"] %}
        {% if obj|attr(name)|length %}
        internal enum {{ obj.name|camelize }}{{ suffix }} {
        {% for key in obj|attr(name) %}
            {{ key|camelize }}{{ "," if not loop.last }}
        {% endfor %}
        }
        {% endif %}
        {% endfor %}
        {% endif %}
    {% endfor %}

    {% for obj in objs.values() %}
        {% if obj.labeled %}
        {{ obj_declaration(obj, 'Label', 'private ') }}
        private readonly Lazy<LabeledMetricType<{{ obj|type_name }}>> {{ obj.name|camelize }}Lazy = new Lazy<LabeledMetricType<{{ obj|type_name }}>>(() => new LabeledMetricType<{{ obj|type_name }}>( // generated from {{ obj.identifier() }}
                category: {{ obj.category|csharp }},
                name: {{ obj.name|csharp }},
                submetric: {{ category_name|Camelize }}.{{ obj.name|camelize }}Label,
                disabled: {{ obj.is_disabled()|csharp }},
                lifetime: {{ obj.lifetime|csharp }},
                sendInPings: {{ obj.send_in_pings|csharp }},
                labels: {{ obj.labels|csharp }}
            )
        );

        /// <summary>
        /// {{ obj.description|wordwrap() | replace('\n', '\n        /// ') }}
        /// </summary>
        public LabeledMetricType<{{ obj|type_name }}> {{ obj.name|camelize }} => {{ obj.name|camelize }}Lazy.Value;

        {% else %}
        {# Deal with non-ping objects first. We need them to be lazy and we
        want their description to stick on an accessor object. #}
        {% if obj.type != 'ping' %}
        {{ obj_declaration(obj, access='private readonly', suffix='Lazy', lazy=True) }}

        /// <summary>
        /// {{ obj.description|wordwrap() | replace('\n', '\n        /// ') }}
        /// </summary>
        internal {{ obj|type_name }} {{ obj.name|camelize }} => {{ obj.name|camelize }}Lazy.Value; // generated from {{ obj.identifier() }}

        {% else %}
        {# Finally handle pings. #}
        /// <summary>
        /// {{ obj.description|wordwrap() | replace('\n', '\n        /// ') }}
        /// </summary>
        {{ obj_declaration(obj, access='internal readonly', lazy=False) }}

        {% endif %}
        {% endif %}
    {%- endfor %}
#pragma warning restore IDE1006 // Naming Styles
    }
}
