syntax = "proto3";

import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";

package laborato.mesh.service;

// Stream synchronization between master service and WSL agent on concrete machine
service WslControlService {
    rpc WslControlStream(stream WslControlAgentMessage) returns (stream WslControlMasterMessage);
}

message WslControlAgentMessage {
    oneof payload {
        WslAgentHello hello = 1;
        WslCommandAccepted accepted = 2;
        WslCommandCompleted completed = 3;
        WslStatusResult status_result = 4;
        WslDistributionsResult distributions_result = 5;
        WslGlobalConfigResult global_config_result = 6;
        WslDistributionConfigResult distribution_config_result = 7;
        WslActivityLogResult activity_log_result = 8;
        WslComplianceResult compliance_result = 9;
        WslAgentHeartbeat heartbeat = 10;
    }
}

message WslControlMasterMessage {
    oneof payload {
        ImportDistributionCommand import_distribution = 1;
        UnregisterDistributionCommand unregister_distribution = 2;
        TerminateDistributionCommand terminate_distribution = 3;
        ShutdownWslCommand shutdown_wsl = 4;
        UpdateWslEngineCommand update_wsl_engine = 5;
        UpdateDistributionPackagesCommand update_distribution_packages = 6;
        ApplyGlobalConfigCommand apply_global_config = 7;
        ApplyDistributionConfigCommand apply_distribution_config = 8;

        GetWslStatusCommand get_wsl_status = 9;
        GetDistributionsCommand get_distributions = 10;
        GetGlobalConfigCommand get_global_config = 11;
        GetDistributionConfigCommand get_distribution_config = 12;
        GetActivityLogCommand get_activity_log = 13;
        GetComplianceCommand get_compliance = 14;
    }
}

message WslAgentHello {
    string agent_id = 1;
    string host_name = 2;
    google.protobuf.StringValue agent_version = 3;
    google.protobuf.StringValue os_version = 4;
}

message WslAgentHeartbeat {
    string agent_id = 1;
    google.protobuf.Timestamp utc_time = 2;
}

message WslCommandAccepted {
    string command_id = 1;
}

message WslCommandCompleted {
    string command_id = 1;
    WslResponseStatus status = 2;
    google.protobuf.StringValue error_message = 3;
}

message ImportDistributionCommand {
    string command_id = 1;
    string distribution_name = 2;
    string install_location = 3;
    string package_path = 4;
    WslDistributionVersion version = 5;
}

message UnregisterDistributionCommand {
    string command_id = 1;
    string distribution_name = 2;
}

message TerminateDistributionCommand {
    string command_id = 1;
    string distribution_name = 2;
}

message ShutdownWslCommand {
    string command_id = 1;
}

message UpdateWslEngineCommand {
    string command_id = 1;
}

message UpdateDistributionPackagesCommand {
    string command_id = 1;
    string distribution_name = 2;
}

message ApplyGlobalConfigCommand {
    string command_id = 1;
    WslGlobalConfig config = 2;
}

message ApplyDistributionConfigCommand {
    string command_id = 1;
    string distribution_name = 2;
    WslDistributionConfig config = 3;
}

message GetWslStatusCommand {
    string command_id = 1;
}

message GetDistributionsCommand {
    string command_id = 1;
}

message GetGlobalConfigCommand {
    string command_id = 1;
}

message GetDistributionConfigCommand {
    string command_id = 1;
    string distribution_name = 2;
}

message GetActivityLogCommand {
    string command_id = 1;
    uint32 max_events = 2;
    google.protobuf.StringValue log_name_filter = 3;
}

message GetComplianceCommand {
    string command_id = 1;
    google.protobuf.StringValue distribution_name = 2;
    WslGlobalConfig expected_global_config = 3;
    WslDistributionConfig expected_distribution_config = 4;
}

message WslStatusResult {
    string command_id = 1;
    WslResponseStatus status = 2;
    WslStatusInfo info = 3;
    google.protobuf.StringValue error_message = 4;
}

message WslDistributionsResult {
    string command_id = 1;
    WslResponseStatus status = 2;
    repeated WslDistributionInfo distributions = 3;
    google.protobuf.StringValue error_message = 4;
}

message WslGlobalConfigResult {
    string command_id = 1;
    WslResponseStatus status = 2;
    WslGlobalConfig config = 3;
    google.protobuf.StringValue raw_text = 4;
    google.protobuf.StringValue error_message = 5;
}

message WslDistributionConfigResult {
    string command_id = 1;
    WslResponseStatus status = 2;
    WslDistributionConfig config = 3;
    google.protobuf.StringValue raw_text = 4;
    google.protobuf.StringValue error_message = 5;
}

message WslActivityLogResult {
    string command_id = 1;
    WslResponseStatus status = 2;
    repeated WslActivityEvent events = 3;
    repeated string discovered_logs = 4;
    google.protobuf.StringValue error_message = 5;
}

message WslComplianceResult {
    string command_id = 1;
    WslResponseStatus status = 2;
    WslComplianceReport report = 3;
    google.protobuf.StringValue error_message = 4;
}

message WslStatusInfo {
    string raw_text = 1;
}

message WslDistributionInfo {
    string distribution_name = 1;
    string state = 2;
    uint32 version = 3;
    bool is_default = 4;
}

message WslGlobalConfig {
    google.protobuf.StringValue memory = 1;
    google.protobuf.UInt32Value processors = 2;
    google.protobuf.StringValue swap = 3;
    google.protobuf.StringValue swap_file = 4;
    google.protobuf.StringValue default_vhd_size = 5;
    WslNetworkingMode networking_mode = 6;
    google.protobuf.BoolValue firewall = 7;
    google.protobuf.BoolValue dns_tunneling = 8;
    google.protobuf.BoolValue auto_proxy = 9;
}

message WslDistributionConfig {
    google.protobuf.BoolValue disable_windows_interop = 1;
    google.protobuf.BoolValue disable_append_windows_path = 2;
    google.protobuf.BoolValue disable_auto_mount_windows_drives = 3;
    google.protobuf.BoolValue mount_fstab = 4;
    google.protobuf.BoolValue generate_hosts = 5;
    google.protobuf.BoolValue generate_resolv_conf = 6;
}

message WslActivityEvent {
    string log_name = 1;
    google.protobuf.StringValue provider_name = 2;
    uint32 event_id = 3;
    google.protobuf.StringValue level = 4;
    google.protobuf.Timestamp time_created = 5;
    google.protobuf.StringValue machine_name = 6;
    google.protobuf.StringValue message = 7;
}

message WslComplianceReport {
    bool wsl_command_available = 1;
    string status_text = 2;
    repeated WslDistributionInfo distributions = 3;

    WslGlobalConfig actual_global_config = 4;
    WslDistributionConfig actual_distribution_config = 5;

    google.protobuf.StringValue actual_global_config_raw = 6;
    google.protobuf.StringValue actual_distribution_config_raw = 7;

    bool global_config_matches_expected = 8;
    bool distribution_config_matches_expected = 9;

    WslMdeHealthcheckInfo mde_healthcheck = 10;
    repeated string issues = 11;
}

message WslMdeHealthcheckInfo {
    bool available = 1;
    int32 exit_code = 2;
    string std_out = 3;
    string std_err = 4;
}

enum WslResponseStatus {
    WSL_RESPONSE_STATUS_OK = 0;
    WSL_RESPONSE_STATUS_ERROR = 1;
}

enum WslDistributionVersion {
    WSL_DISTRIBUTION_VERSION_UNSPECIFIED = 0;
    WSL_DISTRIBUTION_VERSION_1 = 1;
    WSL_DISTRIBUTION_VERSION_2 = 2;
}

enum WslNetworkingMode {
    WSL_NETWORKING_MODE_UNSPECIFIED = 0;
    WSL_NETWORKING_MODE_NONE = 1;
    WSL_NETWORKING_MODE_NAT = 2;
    WSL_NETWORKING_MODE_MIRRORED = 3;
    WSL_NETWORKING_MODE_VIRTIO_PROXY = 4;
}