// This file is generated by TypeBuilder_h.template.

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef content_protocol_WebMCP_h
#define content_protocol_WebMCP_h

#include "content/common/content_export.h"
#include "content/browser/devtools/protocol/protocol.h"
// For each imported domain we generate a ValueConversions struct instead of a full domain definition
// and include Domain::API version from there.
#include "content/browser/devtools/protocol/runtime.h"
#include "content/browser/devtools/protocol/page.h"
#include "content/browser/devtools/protocol/dom.h"

namespace content {
namespace protocol {
namespace WebMCP {
class Annotation;
using InvocationStatus = String;
class Tool;
class RemovedTool;

// ------------- Forward and enum declarations.

namespace InvocationStatusEnum {
inline constexpr char Completed[] = "Completed";
inline constexpr char Canceled[] = "Canceled";
inline constexpr char Error[] = "Error";
} // namespace InvocationStatusEnum

// ------------- Type and builder declarations.

class CONTENT_EXPORT Annotation : public ::crdtp::ProtocolObject<Annotation> {
public:
    ~Annotation() override;  // Defined below

    bool HasReadOnly() { return !!m_readOnly; }
    bool GetReadOnly(bool defaultValue) const {
       return m_readOnly.value_or(defaultValue);
    }
    const std::optional<bool>& GetReadOnly() const {
       return m_readOnly;
    }
    void SetReadOnly(bool value);  // Defined below

    bool HasUntrustedContent() { return !!m_untrustedContent; }
    bool GetUntrustedContent(bool defaultValue) const {
       return m_untrustedContent.value_or(defaultValue);
    }
    const std::optional<bool>& GetUntrustedContent() const {
       return m_untrustedContent;
    }
    void SetUntrustedContent(bool value);  // Defined below

    bool HasConsequential() { return !!m_consequential; }
    bool GetConsequential(bool defaultValue) const {
       return m_consequential.value_or(defaultValue);
    }
    const std::optional<bool>& GetConsequential() const {
       return m_consequential;
    }
    void SetConsequential(bool value);  // Defined below

    bool HasAutosubmit() { return !!m_autosubmit; }
    bool GetAutosubmit(bool defaultValue) const {
       return m_autosubmit.value_or(defaultValue);
    }
    const std::optional<bool>& GetAutosubmit() const {
       return m_autosubmit;
    }
    void SetAutosubmit(bool value);  // Defined below

    template<int STATE>
    class AnnotationBuilder {
    public:
        enum {
            NoFieldsSet = 0,
            AllFieldsSet = (0)};


        AnnotationBuilder<STATE>& SetReadOnly(bool value);  // Defined below

        AnnotationBuilder<STATE>& SetUntrustedContent(bool value);  // Defined below

        AnnotationBuilder<STATE>& SetConsequential(bool value);  // Defined below

        AnnotationBuilder<STATE>& SetAutosubmit(bool value);  // Defined below

        std::unique_ptr<Annotation> Build()
        {
            static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
            return std::move(m_result);
        }

    private:
        friend class Annotation;
        AnnotationBuilder() : m_result(new Annotation()) { }

        template<int STEP> AnnotationBuilder<STATE | STEP>& castState()
        {
            return *reinterpret_cast<AnnotationBuilder<STATE | STEP>*>(this);
        }

        std::unique_ptr<protocol::WebMCP::Annotation> m_result;
    };

    static AnnotationBuilder<0> Create()
    {
        return AnnotationBuilder<0>();
    }

private:
    DECLARE_SERIALIZATION_SUPPORT();

    Annotation();  // Defined below

    std::optional<bool> m_readOnly;
    std::optional<bool> m_untrustedContent;
    std::optional<bool> m_consequential;
    std::optional<bool> m_autosubmit;
};


class CONTENT_EXPORT Tool : public ::crdtp::ProtocolObject<Tool> {
public:
    ~Tool() override;  // Defined below

    String GetName() { return m_name; }
    void SetName(const String& value);  // Defined below

    String GetDescription() { return m_description; }
    void SetDescription(const String& value);  // Defined below

    bool HasInputSchema() { return !!m_inputSchema; }
    protocol::DictionaryValue* GetInputSchema(protocol::DictionaryValue* defaultValue) {
       return m_inputSchema ? m_inputSchema.get() : defaultValue;
    }
    const std::unique_ptr<protocol::DictionaryValue>& GetInputSchema() const {
       return m_inputSchema;
    }
    void SetInputSchema(std::unique_ptr<protocol::DictionaryValue> value);  // Defined below

    bool HasAnnotations() { return !!m_annotations; }
    protocol::WebMCP::Annotation* GetAnnotations(protocol::WebMCP::Annotation* defaultValue) {
       return m_annotations ? m_annotations.get() : defaultValue;
    }
    const std::unique_ptr<protocol::WebMCP::Annotation>& GetAnnotations() const {
       return m_annotations;
    }
    void SetAnnotations(std::unique_ptr<protocol::WebMCP::Annotation> value);  // Defined below

    String GetFrameId() { return m_frameId; }
    void SetFrameId(const String& value);  // Defined below

    bool HasBackendNodeId() { return !!m_backendNodeId; }
    int GetBackendNodeId(int defaultValue) const {
       return m_backendNodeId.value_or(defaultValue);
    }
    const std::optional<int>& GetBackendNodeId() const {
       return m_backendNodeId;
    }
    void SetBackendNodeId(int value);  // Defined below

    bool HasStackTrace() { return !!m_stackTrace; }
    protocol::Runtime::StackTrace* GetStackTrace(protocol::Runtime::StackTrace* defaultValue) {
       return m_stackTrace ? m_stackTrace.get() : defaultValue;
    }
    const std::unique_ptr<protocol::Runtime::StackTrace>& GetStackTrace() const {
       return m_stackTrace;
    }
    void SetStackTrace(std::unique_ptr<protocol::Runtime::StackTrace> value);  // Defined below

    template<int STATE>
    class ToolBuilder {
    public:
        enum {
            NoFieldsSet = 0,
            NameSet = 1 << 1,
            DescriptionSet = 1 << 2,
            FrameIdSet = 1 << 3,
            AllFieldsSet = (NameSet | DescriptionSet | FrameIdSet | 0)};


        ToolBuilder<STATE | NameSet>& SetName(const String& value);  // Defined below

        ToolBuilder<STATE | DescriptionSet>& SetDescription(const String& value);  // Defined below

        ToolBuilder<STATE>& SetInputSchema(std::unique_ptr<protocol::DictionaryValue> value);  // Defined below

        ToolBuilder<STATE>& SetAnnotations(std::unique_ptr<protocol::WebMCP::Annotation> value);  // Defined below

        ToolBuilder<STATE | FrameIdSet>& SetFrameId(const String& value);  // Defined below

        ToolBuilder<STATE>& SetBackendNodeId(int value);  // Defined below

        ToolBuilder<STATE>& SetStackTrace(std::unique_ptr<protocol::Runtime::StackTrace> value);  // Defined below

        std::unique_ptr<Tool> Build()
        {
            static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
            return std::move(m_result);
        }

    private:
        friend class Tool;
        ToolBuilder() : m_result(new Tool()) { }

        template<int STEP> ToolBuilder<STATE | STEP>& castState()
        {
            return *reinterpret_cast<ToolBuilder<STATE | STEP>*>(this);
        }

        std::unique_ptr<protocol::WebMCP::Tool> m_result;
    };

    static ToolBuilder<0> Create()
    {
        return ToolBuilder<0>();
    }

private:
    DECLARE_SERIALIZATION_SUPPORT();

    Tool();  // Defined below

    String m_name;
    String m_description;
    std::unique_ptr<protocol::DictionaryValue> m_inputSchema;
    std::unique_ptr<protocol::WebMCP::Annotation> m_annotations;
    String m_frameId;
    std::optional<int> m_backendNodeId;
    std::unique_ptr<protocol::Runtime::StackTrace> m_stackTrace;
};


class CONTENT_EXPORT RemovedTool : public ::crdtp::ProtocolObject<RemovedTool> {
public:
    ~RemovedTool() override;  // Defined below

    String GetName() { return m_name; }
    void SetName(const String& value);  // Defined below

    String GetFrameId() { return m_frameId; }
    void SetFrameId(const String& value);  // Defined below

    template<int STATE>
    class RemovedToolBuilder {
    public:
        enum {
            NoFieldsSet = 0,
            NameSet = 1 << 1,
            FrameIdSet = 1 << 2,
            AllFieldsSet = (NameSet | FrameIdSet | 0)};


        RemovedToolBuilder<STATE | NameSet>& SetName(const String& value);  // Defined below

        RemovedToolBuilder<STATE | FrameIdSet>& SetFrameId(const String& value);  // Defined below

        std::unique_ptr<RemovedTool> Build()
        {
            static_assert(STATE == AllFieldsSet, "state should be AllFieldsSet");
            return std::move(m_result);
        }

    private:
        friend class RemovedTool;
        RemovedToolBuilder() : m_result(new RemovedTool()) { }

        template<int STEP> RemovedToolBuilder<STATE | STEP>& castState()
        {
            return *reinterpret_cast<RemovedToolBuilder<STATE | STEP>*>(this);
        }

        std::unique_ptr<protocol::WebMCP::RemovedTool> m_result;
    };

    static RemovedToolBuilder<0> Create()
    {
        return RemovedToolBuilder<0>();
    }

private:
    DECLARE_SERIALIZATION_SUPPORT();

    RemovedTool();  // Defined below

    String m_name;
    String m_frameId;
};


// ------------- Type and builder method definitions.
//
// These methods separate from the type declaration because of
// https://github.com/llvm/llvm-project/issues/59966. The DevTools protocol has
// mutually recursive types, so we cannot simply reorder the types.
inline Annotation::~Annotation() = default;
inline void Annotation::SetReadOnly(bool value) { m_readOnly = value; }
inline void Annotation::SetUntrustedContent(bool value) { m_untrustedContent = value; }
inline void Annotation::SetConsequential(bool value) { m_consequential = value; }
inline void Annotation::SetAutosubmit(bool value) { m_autosubmit = value; }

template<int STATE>
inline Annotation::AnnotationBuilder<STATE>& Annotation::AnnotationBuilder<STATE>::SetReadOnly(bool value) {
  m_result->SetReadOnly(value);
  return *this;
}
template<int STATE>
inline Annotation::AnnotationBuilder<STATE>& Annotation::AnnotationBuilder<STATE>::SetUntrustedContent(bool value) {
  m_result->SetUntrustedContent(value);
  return *this;
}
template<int STATE>
inline Annotation::AnnotationBuilder<STATE>& Annotation::AnnotationBuilder<STATE>::SetConsequential(bool value) {
  m_result->SetConsequential(value);
  return *this;
}
template<int STATE>
inline Annotation::AnnotationBuilder<STATE>& Annotation::AnnotationBuilder<STATE>::SetAutosubmit(bool value) {
  m_result->SetAutosubmit(value);
  return *this;
}

inline Annotation::Annotation() {
}
inline Tool::~Tool() = default;
inline void Tool::SetName(const String& value) { m_name = value; }
inline void Tool::SetDescription(const String& value) { m_description = value; }
inline void Tool::SetInputSchema(std::unique_ptr<protocol::DictionaryValue> value) { m_inputSchema = std::move(value); }
inline void Tool::SetAnnotations(std::unique_ptr<protocol::WebMCP::Annotation> value) { m_annotations = std::move(value); }
inline void Tool::SetFrameId(const String& value) { m_frameId = value; }
inline void Tool::SetBackendNodeId(int value) { m_backendNodeId = value; }
inline void Tool::SetStackTrace(std::unique_ptr<protocol::Runtime::StackTrace> value) { m_stackTrace = std::move(value); }

template<int STATE>
inline Tool::ToolBuilder<STATE | Tool::ToolBuilder<STATE>::NameSet>&
Tool::ToolBuilder<STATE>::SetName(const String& value) {
  static_assert(!(STATE & NameSet), "property name should not be set yet");
  m_result->SetName(value);
  return castState<NameSet>();
}
template<int STATE>
inline Tool::ToolBuilder<STATE | Tool::ToolBuilder<STATE>::DescriptionSet>&
Tool::ToolBuilder<STATE>::SetDescription(const String& value) {
  static_assert(!(STATE & DescriptionSet), "property description should not be set yet");
  m_result->SetDescription(value);
  return castState<DescriptionSet>();
}
template<int STATE>
inline Tool::ToolBuilder<STATE>& Tool::ToolBuilder<STATE>::SetInputSchema(std::unique_ptr<protocol::DictionaryValue> value) {
  m_result->SetInputSchema(std::move(value));
  return *this;
}
template<int STATE>
inline Tool::ToolBuilder<STATE>& Tool::ToolBuilder<STATE>::SetAnnotations(std::unique_ptr<protocol::WebMCP::Annotation> value) {
  m_result->SetAnnotations(std::move(value));
  return *this;
}
template<int STATE>
inline Tool::ToolBuilder<STATE | Tool::ToolBuilder<STATE>::FrameIdSet>&
Tool::ToolBuilder<STATE>::SetFrameId(const String& value) {
  static_assert(!(STATE & FrameIdSet), "property frameId should not be set yet");
  m_result->SetFrameId(value);
  return castState<FrameIdSet>();
}
template<int STATE>
inline Tool::ToolBuilder<STATE>& Tool::ToolBuilder<STATE>::SetBackendNodeId(int value) {
  m_result->SetBackendNodeId(value);
  return *this;
}
template<int STATE>
inline Tool::ToolBuilder<STATE>& Tool::ToolBuilder<STATE>::SetStackTrace(std::unique_ptr<protocol::Runtime::StackTrace> value) {
  m_result->SetStackTrace(std::move(value));
  return *this;
}

inline Tool::Tool() {
}
inline RemovedTool::~RemovedTool() = default;
inline void RemovedTool::SetName(const String& value) { m_name = value; }
inline void RemovedTool::SetFrameId(const String& value) { m_frameId = value; }

template<int STATE>
inline RemovedTool::RemovedToolBuilder<STATE | RemovedTool::RemovedToolBuilder<STATE>::NameSet>&
RemovedTool::RemovedToolBuilder<STATE>::SetName(const String& value) {
  static_assert(!(STATE & NameSet), "property name should not be set yet");
  m_result->SetName(value);
  return castState<NameSet>();
}
template<int STATE>
inline RemovedTool::RemovedToolBuilder<STATE | RemovedTool::RemovedToolBuilder<STATE>::FrameIdSet>&
RemovedTool::RemovedToolBuilder<STATE>::SetFrameId(const String& value) {
  static_assert(!(STATE & FrameIdSet), "property frameId should not be set yet");
  m_result->SetFrameId(value);
  return castState<FrameIdSet>();
}

inline RemovedTool::RemovedTool() {
}

// ------------- Backend interface.

class CONTENT_EXPORT Backend {
public:
    virtual ~Backend() { }

    virtual DispatchResponse Enable() = 0;
    virtual DispatchResponse Disable() = 0;
    class CONTENT_EXPORT InvokeToolCallback {
    public:
        virtual void sendSuccess(const String& invocationId) = 0;
        virtual void sendFailure(const DispatchResponse&) = 0;
        virtual void fallThrough() = 0;
        virtual ~InvokeToolCallback() { }
    };
    virtual void InvokeTool(const String& in_frameId, const String& in_toolName, std::unique_ptr<protocol::DictionaryValue> in_input, std::unique_ptr<InvokeToolCallback> callback) = 0;
    virtual DispatchResponse CancelInvocation(const String& in_invocationId) = 0;

};

// ------------- Frontend interface.

class CONTENT_EXPORT Frontend {
public:
  explicit Frontend(FrontendChannel* frontend_channel) : frontend_channel_(frontend_channel) {}
    void ToolsAdded(std::unique_ptr<protocol::Array<protocol::WebMCP::Tool>> tools);
    void ToolsRemoved(std::unique_ptr<protocol::Array<protocol::WebMCP::RemovedTool>> tools);
    void ToolInvoked(const String& toolName, const String& frameId, const String& invocationId, const String& input);
    void ToolResponded(const String& invocationId, const String& status, std::unique_ptr<protocol::Value> output = {}, std::optional<String> errorText = {}, std::unique_ptr<protocol::Runtime::RemoteObject> exception = {});

  void flush();
  void sendRawNotification(std::unique_ptr<Serializable>);
 private:
  FrontendChannel* frontend_channel_;
};

// ------------- Dispatcher.

class CONTENT_EXPORT Dispatcher {
public:
    static void wire(UberDispatcher*, Backend*);

private:
    Dispatcher() { }
};

// ------------- Metainfo.

class CONTENT_EXPORT Metainfo {
public:
    using BackendClass = Backend;
    using FrontendClass = Frontend;
    using DispatcherClass = Dispatcher;
    static const char domainName[];
    static const char commandPrefix[];
    static const char version[];
};

} // namespace WebMCP
} // namespace content
} // namespace protocol

#endif // !defined(content_protocol_WebMCP_h)
