syntax = "proto3";

package blogpost;

import "public_messages.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";

option csharp_namespace = "CMSMicroservice.Protobuf.Protos.BlogPost";

service BlogPostContract
{
    rpc CreateBlogPost(CreateBlogPostRequest) returns (CreateBlogPostResponse){
        option (google.api.http) = { post: "/CreateBlogPost" body: "*" };
    };
    rpc UpdateBlogPost(UpdateBlogPostRequest) returns (google.protobuf.Empty){
        option (google.api.http) = { put: "/UpdateBlogPost" body: "*" };
    };
    rpc DeleteBlogPost(DeleteBlogPostRequest) returns (google.protobuf.Empty){
        option (google.api.http) = { delete: "/DeleteBlogPost" body: "*" };
    };
    rpc GetBlogPost(GetBlogPostRequest) returns (GetBlogPostResponse){
        option (google.api.http) = { get: "/GetBlogPost" };
    };
    rpc GetBlogPostBySlug(GetBlogPostBySlugRequest) returns (GetBlogPostResponse){
        option (google.api.http) = { get: "/GetBlogPostBySlug" };
    };
    rpc GetAllBlogPosts(GetAllBlogPostsRequest) returns (GetAllBlogPostsResponse){
        option (google.api.http) = { get: "/GetAllBlogPosts" };
    };
    rpc GetPublishedBlogPosts(GetPublishedBlogPostsRequest) returns (GetAllBlogPostsResponse){
        option (google.api.http) = { get: "/GetPublishedBlogPosts" };
    };
    rpc GetFeaturedBlogPosts(GetFeaturedBlogPostsRequest) returns (GetAllBlogPostsResponse){
        option (google.api.http) = { get: "/GetFeaturedBlogPosts" };
    };
    rpc PublishBlogPost(PublishBlogPostRequest) returns (PublishBlogPostResponse){
        option (google.api.http) = { post: "/PublishBlogPost" body: "*" };
    };
    rpc ArchiveBlogPost(ArchiveBlogPostRequest) returns (ArchiveBlogPostResponse){
        option (google.api.http) = { post: "/ArchiveBlogPost" body: "*" };
    };
    rpc IncrementViewCount(IncrementViewCountRequest) returns (google.protobuf.Empty){
        option (google.api.http) = { post: "/IncrementViewCount" body: "*" };
    };
}

// ── Create ──
message CreateBlogPostRequest
{
    string title = 1;
    string slug = 2;
    google.protobuf.StringValue summary = 3;
    string html_content = 4;
    google.protobuf.StringValue featured_image_path = 5;
    google.protobuf.StringValue featured_image_thumbnail_path = 6;
    repeated int64 category_ids = 7;
    repeated int64 tag_ids = 8;
    bool is_featured = 9;
    int32 sort_order = 10;
    BlogImageFileModel image_file = 11;
}
message CreateBlogPostResponse
{
    int64 id = 1;
}

// ── Update ──
message UpdateBlogPostRequest
{
    int64 id = 1;
    string title = 2;
    string slug = 3;
    google.protobuf.StringValue summary = 4;
    string html_content = 5;
    google.protobuf.StringValue featured_image_path = 6;
    google.protobuf.StringValue featured_image_thumbnail_path = 7;
    repeated int64 category_ids = 8;
    repeated int64 tag_ids = 9;
    bool is_featured = 10;
    int32 sort_order = 11;
    BlogImageFileModel image_file = 12;
}

// ── Delete ──
message DeleteBlogPostRequest
{
    int64 id = 1;
}

// ── Get Single ──
message GetBlogPostRequest
{
    int64 id = 1;
}
message GetBlogPostBySlugRequest
{
    string slug = 1;
}
message GetBlogPostResponse
{
    int64 id = 1;
    string title = 2;
    string slug = 3;
    google.protobuf.StringValue summary = 4;
    string html_content = 5;
    google.protobuf.StringValue featured_image_path = 6;
    google.protobuf.StringValue featured_image_thumbnail_path = 7;
    int32 status = 8;
    string status_name = 9;
    google.protobuf.Timestamp published_at = 10;
    int32 view_count = 11;
    int64 author_user_id = 12;
    bool is_featured = 13;
    int32 sort_order = 14;
    google.protobuf.Timestamp created = 15;
    google.protobuf.Timestamp last_modified = 16;
    repeated BlogPostCategoryInfo categories = 17;
    repeated BlogPostTagInfo tags = 18;
}
message BlogPostCategoryInfo
{
    int64 id = 1;
    string title = 2;
    string slug = 3;
}
message BlogPostTagInfo
{
    int64 id = 1;
    string title = 2;
    string name = 3;
}

// ── Get All (Admin) ──
message GetAllBlogPostsRequest
{
    messages.PaginationState pagination_state = 1;
    google.protobuf.StringValue sort_by = 2;
    GetAllBlogPostsFilter filter = 3;
}
message GetAllBlogPostsFilter
{
    google.protobuf.StringValue search_term = 1;
    google.protobuf.Int32Value status = 2;
    google.protobuf.Int64Value category_id = 3;
    google.protobuf.BoolValue is_featured = 4;
}
message GetAllBlogPostsResponse
{
    messages.MetaData meta_data = 1;
    repeated BlogPostListItem models = 2;
}
message BlogPostListItem
{
    int64 id = 1;
    string title = 2;
    string slug = 3;
    google.protobuf.StringValue summary = 4;
    google.protobuf.StringValue featured_image_thumbnail_path = 5;
    int32 status = 6;
    string status_name = 7;
    google.protobuf.Timestamp published_at = 8;
    int32 view_count = 9;
    bool is_featured = 10;
    google.protobuf.Timestamp created = 11;
    repeated BlogPostCategoryInfo categories = 12;
}

// ── Get Published (Customer) ──
message GetPublishedBlogPostsRequest
{
    messages.PaginationState pagination_state = 1;
    google.protobuf.StringValue search_term = 2;
    google.protobuf.Int64Value category_id = 3;
}

// ── Get Featured ──
message GetFeaturedBlogPostsRequest
{
    int32 count = 1;
}

// ── Publish ──
message PublishBlogPostRequest
{
    int64 id = 1;
}
message PublishBlogPostResponse
{
    bool success = 1;
    string message = 2;
    google.protobuf.Timestamp published_at = 3;
}

// ── Archive ──
message ArchiveBlogPostRequest
{
    int64 id = 1;
}
message ArchiveBlogPostResponse
{
    bool success = 1;
    string message = 2;
}

// ── View Count ──
message IncrementViewCountRequest
{
    int64 id = 1;
}

// ── File upload model for binary image uploads from BackOffice ──
message BlogImageFileModel
{
    bytes file = 1;
    string mime = 2;
    string file_name = 3;
}
