/**
 * Per-tenant Agent SDK configuration entity.
 *
 * Stores tenant-specific settings for the Claude Agent SDK engine:
 * - billingMode: 'subscription' (default, operator's Claude login) or 'api_key' (tenant's own Anthropic key)
 * - encryptedApiKey/apiKeyIv: AES-256-GCM encrypted Anthropic API key (only for api_key mode)
 * - approvalTimeoutSeconds: L2 high-risk command auto-approve timeout (default 120s, 0 = wait forever)
 * - toolWhitelist: tenant-level tool override (empty = use RBAC defaults)
 * - toolBlacklist: tenant-level always-denied tools
 */
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';

@Entity('tenant_agent_configs')
export class TenantAgentConfig {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ type: 'varchar', length: 20, unique: true })
  tenantId!: string;

  @Column({ type: 'varchar', length: 20, default: 'subscription' })
  billingMode!: 'subscription' | 'api_key';

  @Column({ type: 'bytea', nullable: true })
  encryptedApiKey!: Buffer | null;

  @Column({ type: 'bytea', nullable: true })
  apiKeyIv!: Buffer | null;

  @Column({ type: 'int', default: 120 })
  approvalTimeoutSeconds!: number;

  @Column({ type: 'varchar', array: true, default: '{}' })
  toolWhitelist!: string[];

  @Column({ type: 'varchar', array: true, default: '{}' })
  toolBlacklist!: string[];

  @CreateDateColumn({ type: 'timestamptz' })
  createdAt!: Date;

  @UpdateDateColumn({ type: 'timestamptz' })
  updatedAt!: Date;
}
