// SPDX-License-Identifier: Apache-2.0
syntax = "proto3";

package substrait.extensions;

import "google/protobuf/any.proto";

option csharp_namespace = "Substrait.Protobuf";
option go_package = "github.com/substrait-io/substrait-go/proto/extensions";
option java_multiple_files = true;
option java_package = "io.substrait.proto";

message SimpleExtensionURI {
  // A surrogate key used in the context of a single plan used to reference the
  // URI associated with an extension.
  uint32 extension_uri_anchor = 1;

  // The URI where this extension YAML can be retrieved. This is the "namespace"
  // of this extension.
  string uri = 2;
}

// Describes a mapping between a specific extension entity and the uri where
// that extension can be found.
message SimpleExtensionDeclaration {
  oneof mapping_type {
    ExtensionType extension_type = 1;
    ExtensionTypeVariation extension_type_variation = 2;
    ExtensionFunction extension_function = 3;
  }

  // Describes a Type
  message ExtensionType {
    // references the extension_uri_anchor defined for a specific extension URI.
    uint32 extension_uri_reference = 1;

    // A surrogate key used in the context of a single plan to reference a
    // specific extension type
    uint32 type_anchor = 2;

    // the name of the type in the defined extension YAML.
    string name = 3;
  }

  message ExtensionTypeVariation {
    // references the extension_uri_anchor defined for a specific extension URI.
    uint32 extension_uri_reference = 1;

    // A surrogate key used in the context of a single plan to reference a
    // specific type variation
    uint32 type_variation_anchor = 2;

    // the name of the type in the defined extension YAML.
    string name = 3;
  }

  message ExtensionFunction {
    // references the extension_uri_anchor defined for a specific extension URI.
    uint32 extension_uri_reference = 1;

    // A surrogate key used in the context of a single plan to reference a
    // specific function
    uint32 function_anchor = 2;

    // A simple name if there is only one impl for the function within the YAML.
    // A compound name, referencing that includes type short names if there is
    // more than one impl per name in the YAML.
    string name = 3;
  }
}

// A generic object that can be used to embed additional extension information
// into the serialized substrait plan.
message AdvancedExtension {
  // An optimization is helpful information that don't influence semantics. May
  // be ignored by a consumer.
  google.protobuf.Any optimization = 1;

  // An enhancement alter semantics. Cannot be ignored by a consumer.
  google.protobuf.Any enhancement = 2;
}
