syntax = "proto3";

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";

package animeshon.webcache.v1alpha1;

option go_package = "github.com/animeapis/go-genproto/webcache/v1alpha1;webcache";
option java_package = "com.animeshon.webcache.v1alpha1";
option java_multiple_files = true;
option ruby_package = "Animeshon::WebCache::v1Alpha1";

service WebCache {
  option (google.api.default_host) = "webcache.animeapis.com";
  
  rpc CreateCache(CreateCacheRequest) returns (Cache) {
    option (google.api.http) = {
      post: "/v1alpha1/caches"
      body: "*"
    };
  }

  rpc ListCaches(ListCachesRequest) returns (ListCachesResponse) {
    option (google.api.http) = {
      get: "/v1alpha1/caches"
    };
  }

  // See https://google.aip.dev/162#referencing-revisions for more information.
  rpc GetCache(GetCacheRequest) returns (Cache) {
    option (google.api.http) = {
      get: "/v1alpha1/{name=caches/*}"
    };
  }

  rpc DeleteCache(DeleteCacheRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1alpha1/{name=caches/*}"
    };
  }
}

// Cache contains meta information about a specific web resource.
message Cache {
  // The name of the cache, idempotently generated from the scheme and uri.
  string name = 1 [(google.api.field_behavior) = REQUIRED];

  // The original scheme indicating the protocol used for the original request.
  string scheme = 2 [(google.api.field_behavior) = REQUIRED];

  // The request uri stripped of the original scheme.
  string uri = 3 [(google.api.field_behavior) = REQUIRED];

  // The response content type indicating the original media type.
  string mime_type = 4;

  // The response code indicating the status of the remote response.
  int32 status_code = 5;

  // The absolute redirect uri indicating any permanent or temporary redirect.
  string redirect_uri = 6;

  // The full resource name of the cached resource.
  string resource = 7;
  
  // The randomly generated revision identifier of this cache.
  // The format is an 8-character hexadecimal string.
  string revision_id = 8 [
    (google.api.field_behavior) = IMMUTABLE,
    (google.api.field_behavior) = OUTPUT_ONLY];

  // The creation time indicating when this revision was created.
  google.protobuf.Timestamp revision_create_time = 9 [
    (google.api.field_behavior) = OUTPUT_ONLY];

  // The expiration time indicating when this revision should no longer be
  // considered valid.
  google.protobuf.Timestamp revision_expire_time = 10 [
    (google.api.field_behavior) = OUTPUT_ONLY];
}

message CreateCacheRequest {
  // The cache to be created.
  Cache cache = 1 [(google.api.field_behavior) = REQUIRED];

  // The time-to-live indicating how long this cache should be considered valid.
  // If set to zero, the cache will not have an expiration time.
  google.protobuf.Duration ttl = 2 [(google.api.field_behavior) = INPUT_ONLY];
}

message ListCachesRequest {
  // If unspecified, server will pick an appropriate default.
  int32 page_size = 1;

  // The value returned from the previous call.
  string page_token = 2;

  // A filter to be applied to results.
  //
  // Currently accepted filters include:
  // - uri:{absolute uri}
  // - resource:{full resource name}
  string filter = 3;

  // Whether to return only the latest revision for each cache.
  bool only_latest_revision = 4;
}

message ListCachesResponse {
  // The list of caches.
  repeated Cache caches = 1;

  // A token to retrieve next page of results.
  string next_page_token = 2;
}

message GetCacheRequest {
  // The resource name of the requested cache.
  string name = 1 [(google.api.field_behavior) = REQUIRED];
}

message DeleteCacheRequest {
  // The name of the cache to delete.
  string name = 1 [(google.api.field_behavior) = REQUIRED];
}