syntax = "proto3";

package reddit.devvit.app_permission.v1;

import "google/protobuf/timestamp.proto";

option go_package = "github.snooguts.net/reddit/devplatform-api/go/grpc/devvit/app_permission/v1;app_permission";

message AppPermission {
  string app_slug = 1;
  string subreddit_id = 2;
  repeated Scope scopes = 3;
  ConsentStatus consent_status = 4;
  google.protobuf.Timestamp updated_at = 5;
}

message DevvitApp {
  string app_slug = 1;
  string app_name = 2;
  optional string terms_and_conditions = 3;
  optional string privacy_policy = 4;
}

message GetAppPermissionsByUserIdRequest {
  string user_id = 1;
}

message GetAppPermissionsByUserIdResponse {
  repeated AppPermission app_permissions = 1;
  repeated DevvitApp devvit_apps = 2;
}

message GrantAppPermissionRequest {
  string user_id = 1;
  string app_slug = 2;
  string subreddit_id = 3;
  repeated Scope scopes = 4;
}

message GrantAppPermissionResponse {
  ErrorMessage error = 1;
}

message RevokeAppPermissionRequest {
  string app_slug = 1;
  string user_id = 2;
  string subreddit_id = 3;
}

message RevokeAppPermissionResponse {
  ErrorMessage error = 1;
}

message ErrorMessage {
  string message = 1;
}

// This enum is used to represent the consent status of an app permission.
enum ConsentStatus {
  // The consent status is unknown, which means it has not been set or is not applicable.
  CONSENT_STATUS_UNKNOWN = 0;
  // The user has explicitly denied consent for the app permissions.
  REVOKED = 1;
  // The user has granted consent for the app permissions.
  GRANTED = 2;
}

// This enum is used to represent the scopes of permissions that can be granted to an app.
enum Scope {
  // The scope is unknown, which means it has not been set or is not applicable.
  SCOPE_UNKNOWN = 0;
  // Allows the app to submit posts on behalf of the user.
  SUBMIT_POST = 1;
  // Allows the app to submit comments on behalf of the user.
  SUBMIT_COMMENT = 2;
  // Allows the app to subscribe the user to a subreddit.
  SUBSCRIBE_TO_SUBREDDIT = 3;
}
