syntax = "proto3";

package svc.organization.v1;

import "types/v1/cursor.proto";
import "types/v1/environment.proto";
import "types/v1/organization.proto";
import "types/v1/payment_method.proto";
import "types/v1/product.proto";
import "types/v1/subscription.proto";
import "types/v1/user.proto";

option go_package = "svc/organization/v1;organizationv1";

service OrganizationService {
  rpc CreateEnvironment(CreateEnvironmentRequest) returns (CreateEnvironmentResponse) {}
  rpc GetEnvironment(GetEnvironmentRequest) returns (GetEnvironmentResponse) {}
  rpc ListEnvironment(ListEnvironmentRequest) returns (ListEnvironmentResponse) {}

  rpc ListUser(ListUserRequest) returns (ListUserResponse) {}
  rpc InviteUser(InviteUserRequest) returns (InviteUserResponse) {}
  rpc RevokeUser(RevokeUserRequest) returns (RevokeUserResponse) {}

  rpc CreateAddonSubscription(CreateAddonSubscriptionRequest) returns (CreateAddonSubscriptionResponse) {}
  rpc ListAddonSubscription(ListAddonSubscriptionRequest) returns (ListAddonSubscriptionResponse) {}
  rpc RemoveAddonSubscription(RemoveAddonSubscriptionRequest) returns (RemoveAddonSubscriptionResponse) {}

  // payment
  rpc GetStripePublishableKey(GetStripePublishableKeyRequest) returns (GetStripePublishableKeyResponse) {}
  rpc GetStripeBillingPortal(GetStripeBillingPortalRequest) returns (GetStripeBillingPortalResponse) {}
  rpc CreateStripeCustomerSession(CreateStripeCustomerSessionRequest) returns (CreateStripeCustomerSessionResponse) {}
  rpc ListPaymentMethod(ListPaymentMethodRequest) returns (ListPaymentMethodResponse) {}
}

message CreateEnvironmentRequest {
  message Stripe {
    string confirmation_token = 1;
    string price_id = 2;
  }

  string environment_name = 1;
  oneof payment {
    Stripe stripe = 201;
  }
}

message CreateEnvironmentResponse {
  message Stripe {
    string status = 1;
    string client_secret = 2;
  }

  types.v1.Environment environment = 1;
  oneof payment {
    Stripe stripe = 201;
  }
}

message GetEnvironmentRequest {
  oneof by {
    int64 id = 1;
    string name = 2;
  }
}

message GetEnvironmentResponse {
  types.v1.Environment environment = 1;
}

message ListEnvironmentRequest {
  types.v1.Cursor cursor = 1;
  int32 limit = 2;
}

message ListEnvironmentResponse {
  types.v1.Cursor next = 1;
  message ListItem {
    types.v1.Environment environment = 1;
    types.v1.Product product = 2;
  }
  repeated ListItem items = 2;
}

message ListUserRequest {
  types.v1.Cursor cursor = 1;
  int32 limit = 2;
}

message ListUserResponse {
  types.v1.Cursor next = 1;
  message ListItem {
    types.v1.User user = 1;
  }
  repeated ListItem items = 2;
}

message InviteUserRequest {
  int64 user_email = 1;
}
message InviteUserResponse {}

message RevokeUserRequest {
  int64 user_id = 1;
}
message RevokeUserResponse {}

message CreateAddonSubscriptionRequest {
  message Stripe {
    string confirmation_token = 1;
    string price_id = 2;
  }

  oneof payment {
    Stripe stripe = 201;
  }
}
message CreateAddonSubscriptionResponse {
  message Stripe {
    string status = 1;
    string client_secret = 2;
  }
  oneof payment {
    Stripe stripe = 201;
  }
}

message ListAddonSubscriptionRequest {
  types.v1.Cursor cursor = 1;
  int32 limit = 2;
}
message ListAddonSubscriptionResponse {
  types.v1.Cursor next = 1;
  message ListItem {
    types.v1.Product product = 1;
    types.v1.Subscription subscription = 2;
  }
  repeated ListItem items = 2;
}

message RemoveAddonSubscriptionRequest {
  message Reason {
    string comment = 1;
    string feedback = 2;
  }
  types.v1.Product product = 1;
  optional Reason cancel_reason = 2;
}

message RemoveAddonSubscriptionResponse {}

message GetStripePublishableKeyRequest {}
message GetStripePublishableKeyResponse {
  string stripe_publishable_key = 2;
}

message GetStripeBillingPortalRequest {
  string return_to_url = 1;
}
message GetStripeBillingPortalResponse {
  string return_to_url = 1;
  string portal_url = 2;
}

message CreateStripeCustomerSessionRequest {}
message CreateStripeCustomerSessionResponse {
  string customer_session_client_secret = 1;
}

message ListPaymentMethodRequest {
  types.v1.Cursor cursor = 1;
  int32 limit = 2;
}
message ListPaymentMethodResponse {
  types.v1.Cursor next = 1;
  message ListItem {
    types.v1.PaymentMethod payment_method = 1;
  }
  repeated ListItem items = 2;
}
