syntax = "proto3";

package campaigns.v1;

option go_package = "github.com/gosms-ge/go2-sdk/go/campaigns/v1;campaignsv1";

// CampaignService handles SMS/Email marketing campaigns with bulk trackable links
service CampaignService {
  // List all campaigns
  rpc ListCampaigns(ListCampaignsRequest) returns (ListCampaignsResponse);

  // Create a new campaign
  rpc CreateCampaign(CreateCampaignRequest) returns (Campaign);

  // Get a campaign by ID
  rpc GetCampaign(GetCampaignRequest) returns (Campaign);

  // Update a campaign
  rpc UpdateCampaign(UpdateCampaignRequest) returns (Campaign);

  // Delete a campaign
  rpc DeleteCampaign(DeleteCampaignRequest) returns (DeleteCampaignResponse);

  // Generate links for campaign recipients in bulk
  rpc GenerateLinks(GenerateLinksRequest) returns (GenerateLinksResponse);

  // List campaign links with pagination
  rpc ListCampaignLinks(ListCampaignLinksRequest) returns (ListCampaignLinksResponse);

  // Get campaign statistics
  rpc GetCampaignStats(GetCampaignStatsRequest) returns (CampaignStats);

  // Export all campaign links
  rpc ExportLinks(ExportLinksRequest) returns (ExportLinksResponse);
}

// Campaign represents an SMS/Email marketing campaign
message Campaign {
  string id = 1;
  string user_id = 2;
  string name = 3;
  string description = 4;
  string destination_url = 5;
  bool pass_recipient_id = 6;
  string recipient_param_name = 7;
  int32 total_recipients = 8;
  int64 total_clicks = 9;
  int32 unique_clicks = 10;
  string status = 11; // active, paused, completed, archived
  string created_at = 12;
  string updated_at = 13;
  string expires_at = 14;
}

// CampaignLink represents an individual trackable link for a recipient
message CampaignLink {
  string id = 1;
  string campaign_id = 2;
  string slug = 3;
  string recipient_id = 4;
  string recipient_name = 5;
  map<string, string> recipient_metadata = 6;
  bool clicked = 7;
  string first_clicked_at = 8;
  string last_clicked_at = 9;
  int32 click_count = 10;
  string first_click_platform = 11;
  string first_click_country = 12;
  string first_click_city = 13;
  string created_at = 14;
  string short_url = 15;
}

// Recipient for bulk link generation
message Recipient {
  string id = 1;
  string name = 2;
  map<string, string> metadata = 3;
}

// List campaigns
message ListCampaignsRequest {
  int32 limit = 1;
  int32 offset = 2;
  string status = 3; // filter by status
  string search = 4; // search by name
}

message ListCampaignsResponse {
  repeated Campaign campaigns = 1;
  int32 total = 2;
}

// Create campaign
message CreateCampaignRequest {
  string name = 1;
  string description = 2;
  string destination_url = 3;
  bool pass_recipient_id = 4;
  string recipient_param_name = 5;
  string expires_at = 6;
}

// Get campaign
message GetCampaignRequest {
  string id = 1;
}

// Update campaign
message UpdateCampaignRequest {
  string id = 1;
  string name = 2;
  string description = 3;
  string destination_url = 4;
  bool pass_recipient_id = 5;
  string recipient_param_name = 6;
  string status = 7;
  string expires_at = 8;
}

// Delete campaign
message DeleteCampaignRequest {
  string id = 1;
}

message DeleteCampaignResponse {
  bool success = 1;
}

// Generate links
message GenerateLinksRequest {
  string campaign_id = 1;
  repeated Recipient recipients = 2;
}

message GenerateLinksResponse {
  string campaign_id = 1;
  int32 links_created = 2;
  repeated CampaignLink sample_links = 3; // First 10 links as sample
}

// List campaign links
message ListCampaignLinksRequest {
  string campaign_id = 1;
  int32 limit = 2;
  int32 offset = 3;
  bool clicked_only = 4;
  string search = 5; // Search by recipient_id or recipient_name
}

message ListCampaignLinksResponse {
  repeated CampaignLink links = 1;
  int32 total = 2;
}

// Get campaign stats
message GetCampaignStatsRequest {
  string campaign_id = 1;
}

message CampaignStats {
  string campaign_id = 1;
  int32 total_recipients = 2;
  int64 total_clicks = 3;
  int32 unique_clicks = 4;
  double click_rate = 5; // unique_clicks / total_recipients * 100
  map<string, int64> clicks_by_platform = 6;
  map<string, int64> clicks_by_country = 7;
  map<string, int64> clicks_by_day = 8;
}

// Export links
message ExportLinksRequest {
  string campaign_id = 1;
  string format = 2; // csv or json
}

message ExportLinksResponse {
  repeated CampaignLink links = 1;
}
