syntax = "proto3";
option go_package = "github.com/telerik/ai-builder/contextapi/pkg/api/pb";
import "google/protobuf/empty.proto";


message ContextQueryRequest {
    string lib_name = 1;
    string query = 2;
    int32 text_matches_count = 3;
    int32 code_matches_count = 4;
    repeated string allowed_types = 5;
    string component = 6;
    string filters_json = 7;
    bool structured_output = 8;
}

message Item {
    map<string, string> metadata = 1;
    string content = 2;
}

message ContextQueryResponse {
    repeated Item text = 1;
    repeated Item code = 2;
}

message StringArray {
    repeated string values = 1;
}

message CssSearchRequst {
    string query = 1;
    int32 limit = 2;
}

message BuildingBlocksSearchRequest {
    string query = 1;
    string lib_name = 2;
}

message BuildingBlockItem {
    string name = 1;
    string description = 2;
    string code = 3;
}

message BuildingBlocksSearchResponse {
    repeated BuildingBlockItem items = 1;
}

message ThemeGenerateRequest {
    string prompt = 1;
    repeated string images = 2; // base64 data URLs (e.g., "data:image/jpeg;base64,...")
}

message ThemeGenerateResponse {
    string variables_json = 1; // JSON string of nested theme variables
}

message LogEventRequest {
    string event_name = 1;
    map<string, string> fields = 2;
}

message RecordToolUserRequestMessage {
    string tool_name = 1;
}

message ProductInfo {
    int32 id = 1;
    string code = 2;
    string name = 3;
}

message LicenseInfo {
    int32 id = 1;
    string name = 2;
    string type = 3;
    bool active = 4;
}

message SupportPackageInfo {
    int32 id = 1;
    string name = 2;
    string public_name = 3;
    int32 response_time_hours = 4;
    bool active = 5;
    repeated string incident_types = 6;
}

message AvailabilityInfo {
    string license_start = 1;
    string license_end = 2;
    string support_start = 3;
    string support_end = 4;
}

message EntitlementInfo {
    string code = 1;
    ProductInfo product = 2;
    LicenseInfo license = 3;
    SupportPackageInfo support_package = 4;
    repeated AvailabilityInfo availability = 5;
    bool is_license_available = 6;
    bool is_support_available = 7;
}

message UserInfo {
    string user_id = 1;
    string user_email = 2;
}

message ValidateUserLicenseResponse {
    EntitlementInfo entitlement = 1;
    UserInfo user_info = 2;
    bool has_exceeded_rate_limit = 3;
}

service ContextQueryService {
    rpc Query(ContextQueryRequest) returns (StringArray);
    rpc GetApiRefMatches(ContextQueryRequest) returns (StringArray);
    rpc GetDocsMatches(ContextQueryRequest) returns (StringArray);
    rpc IconsSearch(CssSearchRequst) returns (StringArray);
    rpc CssUtilsSearch(CssSearchRequst) returns (StringArray);
    rpc BuildingBlocksSearch(BuildingBlocksSearchRequest) returns (BuildingBlocksSearchResponse);
    rpc GenerateTheme(ThemeGenerateRequest) returns (ThemeGenerateResponse);
    rpc ValidateUserLicense(google.protobuf.Empty) returns (ValidateUserLicenseResponse);
    rpc RecordOrchestratorUserRequest(google.protobuf.Empty) returns (google.protobuf.Empty);
    rpc RecordToolUserRequest(RecordToolUserRequestMessage) returns (google.protobuf.Empty);
    rpc LogEvent(LogEventRequest) returns (google.protobuf.Empty);
}
