syntax = "proto3";

package temporal.api.cloud.nexus.v1;

option go_package = "go.temporal.io/api/cloud/nexus/v1;nexus";
option java_package = "io.temporal.api.cloud.nexus.v1";
option java_multiple_files = true;
option java_outer_classname = "MessageProto";
option ruby_package = "Temporalio::Api::Cloud::Nexus::V1";
option csharp_namespace = "Temporalio.Api.Cloud.Nexus.V1";

import "temporal/api/common/v1/message.proto";
import "temporal/api/cloud/resource/v1/message.proto";
import "google/protobuf/timestamp.proto";

message EndpointSpec {
    // The name of the endpoint. Must be unique within an account.
    // The name must match `^[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9]$`.
    // This field is mutable.
    string name = 1;

    // Indicates where the endpoint should forward received nexus requests to. 
    EndpointTargetSpec target_spec = 2;

    // The set of policies (e.g. authorization) for the endpoint. Each request's caller
    // must match with at least one of the specs to be accepted by the endpoint.
    // This field is mutable.
    repeated EndpointPolicySpec policy_specs = 3;

    // Deprecated: Not supported after v0.4.0 api version. Use description instead.
    // temporal:versioning:max_version=v0.4.0
    string description_deprecated = 4 [deprecated = true];

    // The markdown description of the endpoint - optional.
    // temporal:versioning:min_version=v0.4.0
    temporal.api.common.v1.Payload description = 5;
}

message EndpointTargetSpec {
    oneof variant {
        // A target spec for routing nexus requests to a specific cloud namespace worker.
        WorkerTargetSpec worker_target_spec = 1;
    }
}

message WorkerTargetSpec {
    // The target cloud namespace to route requests to. Namespace must be in same account as the endpoint. This field is mutable.
    string namespace_id = 1;

    // The task queue on the cloud namespace to route requests to. This field is mutable.
    string task_queue = 2;
}

message EndpointPolicySpec {
    oneof variant {
        // A policy spec that allows one caller namespace to access the endpoint.
        AllowedCloudNamespacePolicySpec allowed_cloud_namespace_policy_spec = 1;
    }
}

message AllowedCloudNamespacePolicySpec {
    // The namespace that is allowed to call into this endpoint. Calling namespace must be in same account as the endpoint.
    string namespace_id = 1;
}

// An endpoint that receives and then routes Nexus requests
message Endpoint {
    // The id of the endpoint. This is generated by the server and is immutable.
    string id = 1;

    // The current version of the endpoint specification.
    // The next update operation must include this version.
    string resource_version = 2;

    // The endpoint specification.
    EndpointSpec spec = 3;

    // The current state of the endpoint.
    // For any failed state, reach out to Temporal Cloud support for remediation.
    temporal.api.cloud.resource.v1.ResourceState state = 4;

    // The id of any ongoing async operation that is creating, updating, or deleting the endpoint, if any.
    string async_operation_id = 5;

    // The date and time when the endpoint was created.
    google.protobuf.Timestamp created_time = 6;

    // The date and time when the endpoint was last modified.
    google.protobuf.Timestamp last_modified_time = 7;
}
