syntax = "proto3";

package proto;

option csharp_namespace = "DysonNetwork.Shared.Proto";

import "google/protobuf/timestamp.proto";
import "embed.proto";
import "publisher.proto";

message WebFeedConfig {
    bool scrap_page = 1;
}

message WebFeed {
    string id = 1;
    string url = 2;
    string title = 3;
    optional string description = 4;
    optional google.protobuf.Timestamp verified_at = 5;
    optional LinkEmbed preview = 6;
    WebFeedConfig config = 7;
    string publisher_id = 8;
    optional Publisher publisher = 9;
    google.protobuf.Timestamp created_at = 10;
    google.protobuf.Timestamp updated_at = 11;
    optional google.protobuf.Timestamp deleted_at = 12;
}

message WebArticle {
    string id = 1;
    string title = 2;
    string url = 3;
    optional string author = 4;
    optional bytes meta = 5;
    optional LinkEmbed preview = 6;
    optional string content = 7;
    optional google.protobuf.Timestamp published_at = 8;
    string feed_id = 9;
    optional WebFeed feed = 10;
    google.protobuf.Timestamp created_at = 11;
    google.protobuf.Timestamp updated_at = 12;
    optional google.protobuf.Timestamp deleted_at = 13;
}

message WebFeedSubscription {
    string id = 1;
    string feed_id = 2;
    optional WebFeed feed = 3;
    string account_id = 4;
    google.protobuf.Timestamp created_at = 5;
    google.protobuf.Timestamp updated_at = 6;
}

message ScrapedArticle {
    LinkEmbed link_embed = 1;
    optional string content = 2;
}

message GetWebArticleRequest {
    string id = 1;
}

message GetWebArticleResponse {
    WebArticle article = 1;
}

message GetWebArticleBatchRequest {
    repeated string ids = 1;
}

message GetWebArticleBatchResponse {
    repeated WebArticle articles = 1;
}

message ListWebArticlesRequest {
    string feed_id = 1;
    int32 page_size = 2;
    string page_token = 3;
}

message ListWebArticlesResponse {
    repeated WebArticle articles = 1;
    string next_page_token = 2;
    int32 total_size = 3;
}

message GetRecentArticlesRequest {
    int32 limit = 1;
}

message GetRecentArticlesResponse {
    repeated WebArticle articles = 1;
}

message GetWebFeedRequest {
    oneof identifier {
        string id = 1;
        string url = 2;
    }
}

message GetWebFeedResponse {
    WebFeed feed = 1;
}

message ListWebFeedsRequest {
    string publisher_id = 1;
    int32 page_size = 2;
    string page_token = 3;
}

message ListWebFeedsResponse {
    repeated WebFeed feeds = 1;
    string next_page_token = 2;
    int32 total_size = 3;
}

message ScrapeArticleRequest {
    string url = 1;
}

message ScrapeArticleResponse {
    ScrapedArticle article = 1;
}

message GetLinkPreviewRequest {
    string url = 1;
    bool bypass_cache = 2;
}

message GetLinkPreviewResponse {
    LinkEmbed preview = 1;
}

message InvalidateLinkPreviewCacheRequest {
    string url = 1;
}

message InvalidateLinkPreviewCacheResponse {
    bool success = 1;
}

service WebArticleService {
    rpc GetWebArticle(GetWebArticleRequest) returns (GetWebArticleResponse);
    rpc GetWebArticleBatch(GetWebArticleBatchRequest) returns (GetWebArticleBatchResponse);
    rpc ListWebArticles(ListWebArticlesRequest) returns (ListWebArticlesResponse);
    rpc GetRecentArticles(GetRecentArticlesRequest) returns (GetRecentArticlesResponse);
}

service WebFeedService {
    rpc GetWebFeed(GetWebFeedRequest) returns (GetWebFeedResponse);
    rpc ListWebFeeds(ListWebFeedsRequest) returns (ListWebFeedsResponse);
}

service WebReaderService {
    rpc ScrapeArticle(ScrapeArticleRequest) returns (ScrapeArticleResponse);
    rpc GetLinkPreview(GetLinkPreviewRequest) returns (GetLinkPreviewResponse);
    rpc InvalidateLinkPreviewCache(InvalidateLinkPreviewCacheRequest) returns (InvalidateLinkPreviewCacheResponse);
}
