// common/proto/table_definition.proto
syntax = "proto3";
package komp_ac.table_definition;

import "common.proto";

service TableDefinition {
    rpc PostTableDefinition (PostTableDefinitionRequest) returns (TableDefinitionResponse);
    rpc GetProfileTree (komp_ac.common.Empty) returns (ProfileTreeResponse);
    rpc DeleteTable (DeleteTableRequest) returns (DeleteTableResponse);
}

message TableLink {
    string linked_table_name = 1;
    bool required = 2;
}

message PostTableDefinitionRequest {
    string table_name = 1;
    repeated TableLink links = 2;
    repeated ColumnDefinition columns = 3;
    repeated string indexes = 4;
    string profile_name = 5;
}

message ColumnDefinition {
    string name = 1;
    string field_type = 2;
}

message TableDefinitionResponse {
    bool success = 1;
    string sql = 2;
}

message ProfileTreeResponse {
    message Table {
        int64 id = 1;
        string name = 2;
        repeated string depends_on = 3;
    }

    message Profile {
        string name = 1;
        repeated Table tables = 2;
    }

    repeated Profile profiles = 1;
}

message DeleteTableRequest {
    string profile_name = 1;
    string table_name = 2;
}

message DeleteTableResponse {
    bool success = 1;
    string message = 2;
}
