syntax = "proto3";

package aryshare;
option go_package = "./aryshare";

import "pb/descriptor.proto";
import "pb/validator.proto";

service Ayrshare {
  // 帖子相关 api
  rpc Post(PostRequest) returns (PostResponse);
  rpc GetPost(GetPostRequest) returns (GetPostResponse);

  // 用户相关 api
  rpc GetUser(GetUserRequest) returns (GetUserResponse);
  
  // 用户配置相关 api
  rpc CreateProfile(CreateProfileRequest) returns (CreateProfileResponse);
  rpc GetProfiles(GetProfilesRequest) returns (GetProfilesResponse);
  rpc GenerateJWT(GenerateJWTRequest) returns (GenerateJWTResponse);
}

// Instagram 用户标签（带坐标）
message UserTag {
  string username = 1 [json_name = "username"];
  double x = 2 [json_name = "x"]; // Required for images, cannot be used with Reels
  double y = 3 [json_name = "y"]; // Required for images, cannot be used with Reels
}

// Instagram 特定发布选项
message InstagramOptions {
  bool shareReelsFeed = 1 [json_name = "shareReelsFeed"]; // Whether Reel can appear in both Feed and Reels tabs
  string audioName = 2 [json_name = "audioName"]; // Name of the audio music for Reels
  string thumbNail = 3 [json_name = "thumbNail"]; // URL of the Reel cover image (thumbnail)
  int32 thumbNailOffset = 4 [json_name = "thumbNailOffset"]; // Offset in milliseconds of the thumbnail frame
  bool stories = 5 [json_name = "stories"]; // Whether to post as Instagram Story
  repeated string altText = 6 [json_name = "altText"]; // Array of alternative text for images (up to 1000 chars per image)
  string locationId = 7 [json_name = "locationId"]; // Facebook Page ID or Page name
  repeated UserTag userTags = 8 [json_name = "userTags"]; // Array of user tags with username and coordinates
  repeated string collaborators = 9 [json_name = "collaborators"]; // Array of Instagram usernames (up to 3)
  bool autoResize = 10 [json_name = "autoResize"]; // Auto resize images to 1080x1080px (Max Pack required)
  bool disableComments = 11 [json_name = "disableComments"]; // Disable comments on the published post
}

// TikTok 特定发布选项
message TikTokOptions {
  bool autoAddMusic = 1 [json_name = "autoAddMusic"]; // Whether to automatically add recommended music (image only)
  bool disableComments = 2 [json_name = "disableComments"]; // Whether to disable comments on the published post
  bool disableDuet = 3 [json_name = "disableDuet"]; // Disable duets on the published video (video only)
  bool disableStitch = 4 [json_name = "disableStitch"]; // Disable stitch on the published video (video only)
  bool draft = 5 [json_name = "draft"]; // Whether to create a draft post
  bool isAIGenerated = 6 [json_name = "isAIGenerated"]; // Whether to enable AI-generated content toggle (video only)
  bool isBrandedContent = 7 [json_name = "isBrandedContent"]; // Whether to enable Branded Content toggle
  bool isBrandOrganic = 8 [json_name = "isBrandOrganic"]; // Whether to enable Brand Organic Content toggle
  int32 imageCoverIndex = 9 [json_name = "imageCoverIndex"]; // Index of mediaUrls to be used as cover (image only, default 0)
  string title = 10 [json_name = "title"]; // Title of the post (image only)
  int32 thumbNailOffset = 11 [json_name = "thumbNailOffset"]; // Frame to use for video cover in milliseconds (video only)
  string thumbNail = 12 [json_name = "thumbNail"]; // URL of thumbnail image for video (video only)
  string visibility = 13 [json_name = "visibility"]; // How the post is shared: "public", "private", "followers", "friends" (image only, default "public")
}

// 发布帖子到社交媒体平台
message PostRequest {
  string post = 1 [json_name = "post", (validator.field) = {string_not_empty: true, human_error: "post内容不能为空"}];
  repeated string platforms = 2 [json_name = "platforms", (validator.field) = {repeated_count_min: 1, human_error: "platforms平台列表不能为空"}];
  repeated string mediaUrls = 3 [json_name = "mediaUrls"];
  bool isVideo = 4 [json_name = "isVideo"];
  string scheduleDate = 5 [json_name = "scheduleDate"];
  bool validateScheduled = 6 [json_name = "validateScheduled"];
  bool shortenLinks = 7 [json_name = "shortenLinks"];
  bool disableComments = 8 [json_name = "disableComments"];
  InstagramOptions instagramOptions = 9 [json_name = "instagramOptions"];
  TikTokOptions tikTokOptions = 10 [json_name = "tikTokOptions"];
  string profileKey = 11 [json_name = "profileKey"];
}

// 单个平台的帖子ID响应
message PostId {
  string status = 1 [json_name = "status"];
  string id = 2 [json_name = "id"];
  string cid = 3 [json_name = "cid"];
  string postUrl = 4 [json_name = "postUrl"];
  string platform = 5 [json_name = "platform"];
  string type = 6 [json_name = "type"];
  string owner = 7 [json_name = "owner"];
  string mediaId = 8 [json_name = "mediaId"];
  string ended = 9 [json_name = "ended"];
  string idShare = 10 [json_name = "idShare"];
  bool isVideo = 11 [json_name = "isVideo"];
  int32 usedQuota = 12 [json_name = "usedQuota"];
}

// 帖子项（使用 profile key 时的响应格式）
message PostItem {
  string status = 1 [json_name = "status"];
  repeated string errors = 2 [json_name = "errors"];
  repeated PostId postIds = 3 [json_name = "postIds"];
  string id = 4 [json_name = "id"];
  string refId = 5 [json_name = "refId"];
  string profileTitle = 6 [json_name = "profileTitle"];
  string post = 7 [json_name = "post"];
}

// 发布帖子响应
message PostResponse {
  string status = 1 [json_name = "status"];
  repeated PostItem posts = 2 [json_name = "posts"];
  // 兼容旧版本响应格式（不使用 profile key 时）
  repeated string errors = 3 [json_name = "errors"];
  repeated PostId postIds = 4 [json_name = "postIds"];
  string id = 5 [json_name = "id"];
}

// 获取帖子请求
message GetPostRequest {
  string id = 1 [json_name = "id", (validator.field) = {string_not_empty: true, human_error: "帖子ID不能为空"}];
  string profileKey = 2 [json_name = "profileKey"];
}

// 获取帖子响应
message GetPostResponse {
  string created = 1 [json_name = "created"];
  repeated string errors = 2 [json_name = "errors"];
  string id = 3 [json_name = "id"];
  repeated string mediaUrls = 4 [json_name = "mediaUrls"];
  repeated string platforms = 5 [json_name = "platforms"];
  string post = 6 [json_name = "post"];
  repeated PostId postIds = 7 [json_name = "postIds"];
  string profileTitle = 8 [json_name = "profileTitle"];
  string refId = 9 [json_name = "refId"];
  string scheduleDate = 10 [json_name = "scheduleDate"];
  bool shortenLinks = 11 [json_name = "shortenLinks"];
  string status = 12 [json_name = "status"];
  string type = 13 [json_name = "type"];
}

// 获取用户详情请求
message GetUserRequest {
  string profileKey = 1 [json_name = "profileKey"];
  bool instagramDetails = 2 [json_name = "instagramDetails"];
}

// 时间戳
message Timestamp {
  int64 seconds = 1 [json_name = "_seconds"];
  int64 nanoseconds = 2 [json_name = "_nanoseconds"];
  string utc = 3 [json_name = "utc"];
}

// Twitter 使用情况
message TwitterUsage {
  int32 monthlyUsage = 1 [json_name = "monthlyUsage"];
  int32 monthlyLimit = 2 [json_name = "monthlyLimit"];
  string monthlyReset = 3 [json_name = "monthlyReset"];
}

// 社交媒体账户显示名称和详情
message DisplayName {
  string created = 1 [json_name = "created"];
  string displayName = 2 [json_name = "displayName"];
  string id = 3 [json_name = "id"];
  string platform = 4 [json_name = "platform"];
  string profileUrl = 5 [json_name = "profileUrl"];
  string userImage = 6 [json_name = "userImage"];
  string username = 7 [json_name = "username"];
  string description = 8 [json_name = "description"];
  bool messagingActive = 9 [json_name = "messagingActive"];
  string pageName = 10 [json_name = "pageName"];
  string userId = 11 [json_name = "userId"];
  string mapsUrl = 12 [json_name = "mapsUrl"];
  string placeId = 13 [json_name = "placeId"];
  string reviewUrl = 14 [json_name = "reviewUrl"];
  string igId = 15 [json_name = "igId"];
  string type = 16 [json_name = "type"];
  int32 usedQuota = 17 [json_name = "usedQuota"];
  int32 refreshDaysRemaining = 18 [json_name = "refreshDaysRemaining"];
  string refreshRequired = 19 [json_name = "refreshRequired"];
  bool isEligibleForGeoRestrictions = 20 [json_name = "isEligibleForGeoRestrictions"];
  bool isVerified = 21 [json_name = "isVerified"];
  string subscriptionType = 22 [json_name = "subscriptionType"];
  TwitterUsage twitterUsage = 23 [json_name = "twitterUsage"];
  string verifiedType = 24 [json_name = "verifiedType"];
}

// 获取用户详情响应
message GetUserResponse {
  repeated string activeSocialAccounts = 1 [json_name = "activeSocialAccounts"];
  Timestamp created = 2 [json_name = "created"];
  repeated DisplayName displayNames = 3 [json_name = "displayNames"];
  string email = 4 [json_name = "email"];
  string lastApiCall = 5 [json_name = "lastApiCall"];
  int32 messagingConversationMonthlyCount = 6 [json_name = "messagingConversationMonthlyCount"];
  bool messagingEnabled = 7 [json_name = "messagingEnabled"];
  int32 monthlyApiCalls = 8 [json_name = "monthlyApiCalls"];
  int32 monthlyPostCount = 9 [json_name = "monthlyPostCount"];
  int32 monthlyPostQuota = 10 [json_name = "monthlyPostQuota"];
  int32 monthlyApiCallsQuota = 11 [json_name = "monthlyApiCallsQuota"];
  string refId = 12 [json_name = "refId"];
  string title = 13 [json_name = "title"];
  string lastUpdated = 14 [json_name = "lastUpdated"];
  string nextUpdate = 15 [json_name = "nextUpdate"];
}

// 创建用户配置请求
message CreateProfileRequest {
  string title = 1 [json_name = "title", (validator.field) = {string_not_empty: true, human_error: "title不能为空"}];
  bool messagingActive = 2 [json_name = "messagingActive"];
  bool hideTopHeader = 3 [json_name = "hideTopHeader"];
  string topHeader = 4 [json_name = "topHeader"];
  repeated string disableSocial = 5 [json_name = "disableSocial"];
  bool team = 6 [json_name = "team"];
  string email = 7 [json_name = "email"];
  string subHeader = 8 [json_name = "subHeader"];
  repeated string tags = 9 [json_name = "tags"];
}

// 创建用户配置响应
message CreateProfileResponse {
  string status = 1 [json_name = "status"];
  string title = 2 [json_name = "title"];
  string refId = 3 [json_name = "refId"];
  string profileKey = 4 [json_name = "profileKey"];
  bool messagingActive = 5 [json_name = "messagingActive"];
}

// 获取用户配置列表请求
message GetProfilesRequest {
  string title = 1 [json_name = "title"];
  string refId = 2 [json_name = "refId"];
  bool hasActiveSocialAccounts = 3 [json_name = "hasActiveSocialAccounts"];
  repeated string includesActiveSocialAccounts = 4 [json_name = "includesActiveSocialAccounts"];
  oneof actionLog {
    bool actionLogBool = 5 [json_name = "actionLogBool"];
    int32 actionLogInt = 6 [json_name = "actionLogInt"];
  }
  int32 limit = 7 [json_name = "limit"];
  string cursor = 8 [json_name = "cursor"];
}

// 用户配置项
message ProfileItem {
  string status = 1 [json_name = "status"];
  string title = 2 [json_name = "title"];
  string displayTitle = 3 [json_name = "displayTitle"];
  Timestamp created = 4 [json_name = "created"];
  string createdUTC = 5 [json_name = "createdUTC"];
  string refId = 6 [json_name = "refId"];
  repeated string activeSocialAccounts = 7 [json_name = "activeSocialAccounts"];
  bool suspended = 8 [json_name = "suspended"];
}

// 分页信息
message Pagination {
  bool hasMore = 1 [json_name = "hasMore"];
  string nextCursor = 2 [json_name = "nextCursor"];
  int32 limit = 3 [json_name = "limit"];
}

// 获取用户配置列表响应
message GetProfilesResponse {
  repeated ProfileItem profiles = 1 [json_name = "profiles"];
  int32 count = 2 [json_name = "count"];
  string lastUpdated = 3 [json_name = "lastUpdated"];
  string nextUpdate = 4 [json_name = "nextUpdate"];
  Pagination pagination = 5 [json_name = "pagination"];
}

// 邮件配置对象
message Email {
  string to = 1 [json_name = "to"];
  string subject = 2 [json_name = "subject"];
  string body = 3 [json_name = "body"];
}

// 生成JWT请求
message GenerateJWTRequest {
  string domain = 1 [json_name = "domain", (validator.field) = {string_not_empty: true, human_error: "domain不能为空"}];
  string privateKey = 2 [json_name = "privateKey", (validator.field) = {string_not_empty: true, human_error: "privateKey不能为空"}];
  string profileKey = 3 [json_name = "profileKey", (validator.field) = {string_not_empty: true, human_error: "profileKey不能为空"}];
  bool logout = 4 [json_name = "logout"];
  string redirect = 5 [json_name = "redirect"];
  repeated string allowedSocial = 6 [json_name = "allowedSocial"];
  bool verify = 7 [json_name = "verify"];
  bool base64 = 8 [json_name = "base64"];
  int32 expiresIn = 9 [json_name = "expiresIn"];
  Email email = 10 [json_name = "email"];
}

// 生成JWT响应
message GenerateJWTResponse {
  string status = 1 [json_name = "status"];
  string title = 2 [json_name = "title"];
  string token = 3 [json_name = "token"];
  string url = 4 [json_name = "url"];
  bool emailSent = 5 [json_name = "emailSent"];
  string expiresIn = 6 [json_name = "expiresIn"];
}
