syntax = "proto3";

package configuration;

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

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

service ConfigurationContract
{
    rpc CreateOrUpdateConfiguration(CreateOrUpdateConfigurationRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            post: "/Configuration/CreateOrUpdate"
            body: "*"
        };
    };
    rpc DeactivateConfiguration(DeactivateConfigurationRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            post: "/Configuration/Deactivate"
            body: "*"
        };
    };
    rpc GetConfigurationByKey(GetConfigurationByKeyRequest) returns (GetConfigurationByKeyResponse){
        option (google.api.http) = {
            get: "/Configuration/GetByKey"
        };
    };
    rpc GetAllConfigurations(GetAllConfigurationsRequest) returns (GetAllConfigurationsResponse){
        option (google.api.http) = {
            get: "/Configuration/GetAll"
        };
    };
    rpc GetConfigurationHistory(GetConfigurationHistoryRequest) returns (GetConfigurationHistoryResponse){
        option (google.api.http) = {
            get: "/Configuration/GetHistory"
        };
    };
    
    // Customer-facing APIs
    rpc GetClubConfiguration(google.protobuf.Empty) returns (GetClubConfigurationResponse){
        option (google.api.http) = {
            get: "/Configuration/Customer/Club"
        };
    };
    
    rpc GetClubFeatures(google.protobuf.Empty) returns (GetClubFeaturesResponse){
        option (google.api.http) = {
            get: "/Configuration/Customer/ClubFeatures"
        };
    };
}

// CreateOrUpdate Command
message CreateOrUpdateConfigurationRequest
{
    string key = 1;
    string value = 2;
    google.protobuf.StringValue description = 3;
    int32 scope = 4; // ConfigurationScope enum: System=0, Network=1, Club=2, Commission=3
}

// Deactivate Command
message DeactivateConfigurationRequest
{
    string key = 1;
    google.protobuf.StringValue reason = 2;
}

// GetByKey Query
message GetConfigurationByKeyRequest
{
    int32 scope = 1;
    string key = 2;
}

message GetConfigurationByKeyResponse
{
    int64 id = 1;
    string key = 2;
    string value = 3;
    string description = 4;
    int32 scope = 5;
    bool is_active = 6;
    google.protobuf.Timestamp created = 7;
    google.protobuf.Timestamp last_modified = 8;
}

// GetAll Query
message GetAllConfigurationsRequest
{
    messages.PaginationState pagination_state = 1;
    google.protobuf.StringValue sort_by = 2;
    GetAllConfigurationsFilter filter = 3;
}

message GetAllConfigurationsFilter
{
    google.protobuf.Int32Value scope = 1;
    google.protobuf.StringValue key_contains = 2;
    google.protobuf.BoolValue is_active = 3;
}

message GetAllConfigurationsResponse
{
    messages.MetaData meta_data = 1;
    repeated ConfigurationModel models = 2;
}

message ConfigurationModel
{
    int64 id = 1;
    string key = 2;
    string value = 3;
    string description = 4;
    int32 scope = 5;
    bool is_active = 6;
    google.protobuf.Timestamp created = 7;
}

// GetHistory Query
message GetConfigurationHistoryRequest
{
    google.protobuf.Int64Value configuration_id = 1;
    google.protobuf.StringValue key = 2;
    int32 page_index = 3;
    int32 page_size = 4;
}

message GetConfigurationHistoryResponse
{
    messages.MetaData meta_data = 1;
    repeated ConfigurationHistoryModel models = 2;
}

message ConfigurationHistoryModel
{
    int64 id = 1;
    int64 configuration_id = 2;
    string key = 3;
    string old_value = 4;
    string new_value = 5;
    string old_description = 6;
    string new_description = 7;
    int32 old_scope = 8;
    int32 new_scope = 9;
    string performed_by = 10;
    string reason = 11;
    google.protobuf.Timestamp created = 12;
}

// ============ Customer APIs ============

// GetClubConfiguration - for frontend customer display
message GetClubConfigurationResponse
{
    int64 activation_fee = 1;
    int64 membership_gift_value = 2;
}

// GetClubFeatures - for frontend customer display
message GetClubFeaturesResponse
{
    repeated ClubFeatureModel features = 1;
}

message ClubFeatureModel
{
    int64 id = 1;
    string title = 2;
    string description = 3;
    bool is_enabled = 4;
    int32 display_order = 5;
    google.protobuf.Timestamp granted_at = 6;
    google.protobuf.Timestamp created_at = 7;
    string notes = 8;
}
