//
// Aspia Project
// Copyright (C) 2016-2024 Dmitry Chapyshev <dmitry@aspia.ru>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

syntax = "proto3";

option optimize_for = LITE_RUNTIME;

import "common.proto";
import "desktop.proto";

package proto.address_book;

enum EncryptionType
{
    ENCRYPTION_TYPE_UNKNOWN            = 0;
    ENCRYPTION_TYPE_NONE               = 1;
    ENCRYPTION_TYPE_XCHACHA20_POLY1305 = 2;
    ENCRYPTION_TYPE_CHACHA20_POLY1305  = 3;
}

message SessionConfig
{
    DesktopConfig desktop_manage = 1;
    DesktopConfig desktop_view   = 2;
}

message InheritConfig
{
    bool credentials    = 1;
    bool desktop_manage = 2;
    bool desktop_view   = 3;
}

message Computer
{
    int64 create_time = 1;
    int64 modify_time = 2;
    // Field 3 not used (deprecated).

    string name       = 4;
    string comment    = 5;
    string address    = 6;
    uint32 port       = 7;
    string username   = 8;
    string password   = 9;

    // Fields 10-11 are reserved.

    InheritConfig inherit = 12;

    // Fields 13-15 are reserved.

    // Session configurations.
    SessionType session_type = 16;
    SessionConfig session_config  = 17;
}

message ComputerGroupConfig
{
    InheritConfig inherit = 1;

    string username = 2;
    string password = 3;

    // Fields 4-20 are reserved.

    SessionConfig session_config  = 21;
}

message ComputerGroup
{
    int64 create_time = 1;
    int64 modify_time = 2;

    // List of child computers.
    repeated Computer computer = 3;

    // List of child computer groups.
    repeated ComputerGroup computer_group = 4;

    string name    = 5;
    string comment = 6;
    bool expanded  = 7;

    // Fields 8-20 are reserved.

    ComputerGroupConfig config = 21;
}

message Router
{
    string address  = 1;
    uint32 port     = 2;
    string username = 3;
    string password = 4;
}

message Data
{
    // Field 1 - Deprecated.
    ComputerGroup root_group = 2;
    // Field 3 - Deprecated.

    // Enable or disable router.
    bool enable_router = 4;

    // Connection parameters for the router.
    Router router = 5;

    // Unique GUID for address book.
    string guid = 6;

    // Display name when connected.
    string display_name = 7;
}

message File
{
    // Encryption type.
    EncryptionType encryption_type = 1;

    // Field 2 not used (deprecated).

    // If encryption is enabled, contains salt (random data), which are added at each iteration
    // of the hashing to create the key.
    // When the encryption is disabled, the field is not used.
    bytes hashing_salt = 3;

    // Fields 4-8 are reserved.

    // If the encryption is enabled, it contains serialized and encrypted |Data|.
    // If the encryption is disabled, it contains a serialized |Data|.
    bytes data = 9;
}
