// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1

syntax = "proto3";

// Package store provides protobufs for storing types in the plugin host
// package.
package controller.storage.host.plugin.store.v1;

import "controller/custom_options/v1/options.proto";
import "controller/storage/timestamp/v1/timestamp.proto";

option go_package = "github.com/hashicorp/boundary/internal/host/plugin/store;store";

message HostCatalog {
  // public_id is a surrogate key suitable for use in a public API.
  // @inject_tag: `gorm:"primary_key"`
  string public_id = 1;

  // The create_time is set by the database.
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 2;

  // The update_time is set by the database.
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp update_time = 3;

  // name is optional. If set, it must be unique within project_id.
  // @inject_tag: `gorm:"default:null"`
  string name = 4 [(custom_options.v1.mask_mapping) = {
    this: "name"
    that: "name"
  }];

  // description is optional.
  // @inject_tag: `gorm:"default:null"`
  string description = 5 [(custom_options.v1.mask_mapping) = {
    this: "description"
    that: "description"
  }];

  // The project_id of the owning scope and must be set.
  // @inject_tag: `gorm:"not_null"`
  string project_id = 6;

  // The public id of the plugin this catalog uses.
  // @inject_tag: `gorm:"not_null"`
  string plugin_id = 7;

  // version allows optimistic locking of the resource
  // @inject_tag: `gorm:"default:null"`
  uint32 version = 8;

  // secrets_hmac is a sha256-hmac of the unencrypted secrets that is returned
  // from the API for read.  It is recalculated everytime the raw secrets are
  // updated.
  // @inject_tag: `gorm:"default:null"`
  bytes secrets_hmac = 9;

  // attributes is a jsonb formatted field.
  // @inject_tag: `gorm:"not_null"`
  bytes attributes = 10;

  // worker_filter is optional.
  // @inject_tag: `gorm:"default:null"`
  string worker_filter = 11 [(custom_options.v1.mask_mapping) = {
    this: "WorkerFilter"
    that: "worker_filter"
  }];
}

message HostSet {
  // public_id is a surrogate key suitable for use in a public API.
  // @inject_tag: `gorm:"primary_key"`
  string public_id = 1;

  // The create_time is set by the database.
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 2;

  // The update_time is set by the database.
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp update_time = 3;

  // The last_sync_time is updated every time a host set has been synced.
  // @inject_tag: `gorm:"default:null"`
  timestamp.v1.Timestamp last_sync_time = 4;

  // The need_sync indicates that a sync needs to happen.
  // @inject_tag: `gorm:"not_null"`
  bool need_sync = 5;

  // name is optional. If set, it must be unique within
  // catalog_id.
  // @inject_tag: `gorm:"default:null"`
  string name = 6 [(custom_options.v1.mask_mapping) = {
    this: "name"
    that: "name"
  }];

  // description is optional.
  // @inject_tag: `gorm:"default:null"`
  string description = 7 [(custom_options.v1.mask_mapping) = {
    this: "description"
    that: "description"
  }];

  // catalog_id is the public_id of the owning
  // plugin_host_catalog and must be set.
  // @inject_tag: `gorm:"not_null"`
  string catalog_id = 8;

  // version allows optimistic locking of the resource
  // @inject_tag: `gorm:"default:null"`
  uint32 version = 9;

  // attributes is a byte field containing marshaled JSON data
  // @inject_tag: `gorm:"not_null"`
  bytes attributes = 10;

  // preferred_endpoints stores string preference values
  // @inject_tag: `gorm:"-"`
  repeated string preferred_endpoints = 11 [(custom_options.v1.mask_mapping) = {
    this: "PreferredEndpoints"
    that: "preferred_endpoints"
  }];

  // Sync interval is a value representing a duration in seconds
  // @inject_tag: `gorm:"default:null"`
  int32 sync_interval_seconds = 12 [(custom_options.v1.mask_mapping) = {
    this: "SyncIntervalSeconds"
    that: "sync_interval_seconds"
  }];
}

message HostCatalogSecret {
  // catalog_id is the public id of the catalog containing this secret.
  // @inject_tag: `gorm:"primary_key"`
  string catalog_id = 1;

  // The create_time is set by the database.
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 2;

  // The update_time is set by the database.
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp update_time = 3;

  // attributes is the plain-text of the attribute data.  We are not storing
  // this plain-text value in the database.
  // @inject_tag: `gorm:"-" wrapping:"pt,secret_data"`
  bytes secret = 4;

  // ct_attributes is the ciphertext of the attribute data stored in the db.
  // @inject_tag: `gorm:"column:secret;not_null" wrapping:"ct,secret_data"`
  bytes ct_secret = 5;

  // The key_id of the kms database key used for encrypting this entry.
  // It must be set.
  // @inject_tag: `gorm:"not_null"`
  string key_id = 6;
}

// TODO: Add a field which tracks if the host in cache should be considered
//       invalid and fall back to the plugin provided data.
message Host {
  // public_id is a surrogate key suitable for use in a public API.
  // @inject_tag: `gorm:"primary_key"`
  string public_id = 1;

  // external_id is an id provided by the plugin.
  // @inject_tag: `gorm:"not_null"`
  string external_id = 2;

  // external_name is an optional name provided by the plugin.
  // @inject_tag: `gorm:"default:null"`
  string external_name = 11;

  // The create_time is set by the database.
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 3;

  // The update_time is set by the database.
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp update_time = 4;

  // name is optional. If set, it must be unique within
  // catalog_id.
  // @inject_tag: `gorm:"default:null"`
  string name = 5;

  // description is optional.
  // @inject_tag: `gorm:"default:null"`
  string description = 6;

  // catalog_id is the public_id of the owning
  // plugin_host_catalog and must be set.
  // @inject_tag: `gorm:"not_null"`
  string catalog_id = 7;

  // version allows optimistic locking of the resource
  // @inject_tag: `gorm:"default:null"`
  uint32 version = 8;

  // ip_addresses are the ip addresses associated with this host and will
  // be persisted in the db through the HostAddress message.
  // @inject_tag: `gorm:"-"`
  repeated string ip_addresses = 9;

  // dns_names are the dns names associated with this host and will
  // be persisted in the db through the HostAddress message.
  // @inject_tag: `gorm:"-"`
  repeated string dns_names = 10;
}

message HostSetMember {
  // @inject_tag: `gorm:"primary_key"`
  string host_id = 1;

  // @inject_tag: `gorm:"primary_key"`
  string set_id = 2;

  // @inject_tag: `gorm:"default:null"`
  string catalog_id = 3;
}
