/*
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * 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.
 */

// Autogenerated file -- DO NOT EDIT!

#ifndef PANDA_<%= Common::module.name.upcase %>_EVENTS_GEN_H_
#define PANDA_<%= Common::module.name.upcase %>_EVENTS_GEN_H_

#include <fstream>
#include <array>

namespace <%= Common::module.namespace %> {

class Graph;

class EventWriter {
public:
    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
    EventWriter(std::string_view class_name, std::string_view method_name) {
        std::copy(class_name.begin(), class_name.begin() + std::min(class_name.size(), BUF_SIZE - 1) + 1,
                  class_name_.data());
        std::copy(method_name.begin(), method_name.begin() + std::min(method_name.size(), BUF_SIZE - 1) + 1,
                  method_name_.data());
    }

    static void Init(const std::string& file_path) {
        EventWriter::events_file.open(file_path, std::ios::out);
    }

% Common::events.each do |op|
    void <%= op.method_name %>(<%= op.args_list %>) {
        events_file << class_name_.data() << "::" << method_name_.data() << ',' << "<%= op.name %>" << ',';
        <%= op.print_line %>;
        events_file << std::endl;
    }
% end

public:
    // TODO (a.popov) synchronize object in multithreaded mode
    // NOLINTNEXTLINE(cert-err58-cpp,fuchsia-statically-constructed-objects)
    static inline std::ofstream events_file;

private:
    static constexpr size_t BUF_SIZE = 512;
    std::array<char, BUF_SIZE> class_name_;
    std::array<char, BUF_SIZE> method_name_;
};

}  // namespace <%= Common::module.namespace %>

#endif  // PANDA_<%= Common::module.name.upcase %>_EVENTS_GEN_H_