syntax = "proto3";

package yandex.cloud.loadbalancer.v1;

import "google/protobuf/timestamp.proto";
import "yandex/cloud/validation.proto";
import "yandex/cloud/loadbalancer/v1/health_check.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/loadbalancer/v1;loadbalancer";
option java_package = "yandex.cloud.api.loadbalancer.v1";

// IP version of the addresses that the load balancer works with.
// Only IPv4 is currently available.
enum IpVersion {
  IP_VERSION_UNSPECIFIED = 0;

  // IPv4
  IPV4 = 1;

  // IPv6
  IPV6 = 2;
}

// A NetworkLoadBalancer resource. For more information, see [Network Load Balancer](/docs/network-load-balancer/concepts).
message NetworkLoadBalancer {
  enum Status {
    STATUS_UNSPECIFIED = 0;

    // Network load balancer is being created.
    CREATING = 1;

    // Network load balancer is being started.
    STARTING = 2;

    // Network load balancer is active and sends traffic to the targets.
    ACTIVE = 3;

    // Network load balancer is being stopped.
    STOPPING = 4;

    // Network load balancer is stopped and doesn't send traffic to the targets.
    STOPPED = 5;
    
    // Network load balancer is being deleted.
    DELETING = 6;

    // The load balancer doesn't have any listeners or target groups, or
    // attached target groups are empty. The load balancer doesn't perform any health checks or
    // send traffic in this state.
    INACTIVE = 7;
  }

  // Type of the load balancer. Only external load balancers are currently available.
  enum Type {
    TYPE_UNSPECIFIED = 0;

    // External network load balancer.
    EXTERNAL = 1;

    // Internal network load balancer.
    INTERNAL = 2;
  }

  // Type of session affinity. Only 5-tuple affinity is currently available.
  // For more information, see [Load Balancer concepts](/docs/network-load-balancer/concepts/).
  enum SessionAffinity {
    SESSION_AFFINITY_UNSPECIFIED = 0;

    // 5-tuple affinity.
    CLIENT_IP_PORT_PROTO = 1;
  }

  // ID of the network load balancer.
  string id = 1;

  // ID of the folder that the network load balancer belongs to.
  string folder_id = 2;

  // Creation timestamp in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) text format.
  google.protobuf.Timestamp created_at = 3;

  // Name of the network load balancer. The name is unique within the folder. 3-63 characters long.
  string name = 4;

  // Optional description of the network load balancer. 0-256 characters long.
  string description = 5;

  // Resource labels as `` key:value `` pairs. Maximum of 64 per resource.
  map<string, string> labels = 6;

  // ID of the region that the network load balancer belongs to.
  string region_id = 7;

  // Status of the network load balancer.
  Status status = 9;

  // Type of the network load balancer. Only external network load balancers are available now.
  Type type = 10;

  // Type of the session affinity. Only 5-tuple affinity is available now.
  SessionAffinity session_affinity = 11;

  // List of listeners for the network load balancer.
  repeated Listener listeners = 12;

  // List of target groups attached to the network load balancer.
  repeated AttachedTargetGroup attached_target_groups = 13;
}

// An AttachedTargetGroup resource. For more information, see [Targets and groups](/docs/network-load-balancer/concepts/target-resources).
message AttachedTargetGroup {
  // ID of the target group.
  string target_group_id = 1 [(required) = true, (length) = "<=50"];

  // A health check to perform on the target group.
  // For now we accept only one health check per AttachedTargetGroup.
  repeated HealthCheck health_checks = 2 [(size) = "1"];
}

// A Listener resource. For more information, see [Listener](/docs/network-load-balancer/concepts/listener)
message Listener {
  // Network protocol to use.
  enum Protocol {
    PROTOCOL_UNSPECIFIED = 0;
    TCP = 1;
    UDP = 2;
  }

  // Name of the listener. The name must be unique for each listener on a single load balancer. 3-63 characters long.
  string name = 1;

  // IP address for the listener.
  string address = 2;

  // Port.
  int64 port = 3;

  // Network protocol for incoming traffic.
  Protocol protocol = 4;

  // Port of a target.
  int64 target_port = 5;

  // ID of the subnet.
  string subnet_id = 6;

  // IP version of the external address.
  IpVersion ip_version = 7;
}

// State of the target that was returned after the last health check.
message TargetState {

  // Status of the target.
  enum Status {
    STATUS_UNSPECIFIED = 0;

    // The network load balancer is setting up health checks for this target.
    INITIAL = 1;

    // Health check passed and the target is ready to receive traffic.
    HEALTHY = 2;

    // Health check failed and the target is not receiving traffic.
    UNHEALTHY = 3;

    // Target is being deleted and the network load balancer is no longer sending traffic to this target.
    DRAINING = 4;

    // The network load balancer is stopped and not performing health checks on this target.
    INACTIVE = 5;
  }

  // ID of the subnet that the target is connected to.
  string subnet_id = 1;

  // IP address of the target.
  string address = 2;

  // Status of the target.
  Status status = 3;
}
