// Project is fraser's per-customer isolation unit -- the IA-parity
// public surface for the existing `projects` and `project_members`
// tables that fraser's admin.v1 / Drizzle layer already owns.
syntax = "proto3";

package tars.tenancy.v1;

import "google/api/field_behavior.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/tetrateio/fraser/api/tars/tenancy/v1;tenancyv1";

// ProjectState mirrors CustomerState.
enum ProjectState {
  PROJECT_STATE_UNSPECIFIED = 0;
  PROJECT_STATE_ACTIVE = 1;
  PROJECT_STATE_ARCHIVED = 2;
}

// Project carries the per-customer isolation unit. The natural key is
// (customer_id, project_id); `id` is the server-assigned uuid row key.
message Project {
  // Server-assigned uuid row id. Output-only.
  string id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Owning customer slug. Immutable on update.
  string customer_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Customer-scoped slug. Required on create; immutable thereafter.
  string project_id = 3 [(google.api.field_behavior) = REQUIRED];

  // Human-friendly display name.
  string display_name = 4;

  // Freeform description.
  string description = 5;

  // Lifecycle state.
  ProjectState state = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Freeform labels for filtering / grouping.
  map<string, string> labels = 7;

  // Row creation time. Output-only.
  google.protobuf.Timestamp created_at = 50 [(google.api.field_behavior) = OUTPUT_ONLY];
  // Last mutation time. Output-only.
  google.protobuf.Timestamp updated_at = 51 [(google.api.field_behavior) = OUTPUT_ONLY];
  // Time the project was archived; unset while ACTIVE. Output-only.
  google.protobuf.Timestamp archived_at = 52 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// ProjectMember binds an Identity to a Project with a role. Fraser's
// underlying schema stores the identity as `user_id` (text) and the
// role as one of "admin" or "member"; the proto exposes those values
// as `identity_id` and a free-form role string to match IA's wire
// shape while remaining compatible with the existing `project_members`
// table.
message ProjectMember {
  // Server-assigned uuid row id. Output-only.
  string id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Owning customer slug.
  string customer_id = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Owning project slug.
  string project_id = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Identity row id (authn.user.id). Required on add.
  string identity_id = 4 [(google.api.field_behavior) = REQUIRED];

  // Role bundle. One of "admin", "member". Required on add / update.
  string role = 5 [(google.api.field_behavior) = REQUIRED];

  // Time the identity was added to the project. Output-only.
  google.protobuf.Timestamp created_at = 50 [(google.api.field_behavior) = OUTPUT_ONLY];
  // Last time the membership (e.g. role) changed. Output-only.
  google.protobuf.Timestamp updated_at = 51 [(google.api.field_behavior) = OUTPUT_ONLY];
}
