import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
} from 'typeorm';

@Entity('mcp_server_configs')
@Index('idx_mcp_server_configs_tenant', ['tenantId'])
@Index('idx_mcp_server_configs_enabled', ['tenantId', 'enabled'])
export class McpServerConfigORM {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'tenant_id', type: 'uuid', nullable: true })
  tenantId: string | null;

  @Column({ name: 'server_id', type: 'varchar', length: 100 })
  serverId: string;

  @Column({ type: 'varchar', length: 255 })
  name: string;

  @Column({ type: 'text', nullable: true })
  description: string | null;

  @Column({ type: 'varchar', length: 20 })
  transport: 'stdio' | 'sse';

  @Column({ type: 'varchar', length: 500, nullable: true })
  command: string | null;

  @Column({ type: 'jsonb', nullable: true })
  args: string[] | null;

  @Column({ type: 'jsonb', nullable: true })
  env: Record<string, string> | null;

  @Column({ type: 'varchar', length: 500, nullable: true })
  url: string | null;

  @Column({ name: 'tools_concurrency_safe', type: 'boolean', default: true })
  toolsConcurrencySafe: boolean;

  @Column({ name: 'connect_timeout_ms', type: 'int', default: 10000 })
  connectTimeoutMs: number;

  @Column({ name: 'tool_timeout_ms', type: 'int', default: 30000 })
  toolTimeoutMs: number;

  @Column({ type: 'boolean', default: true })
  enabled: boolean;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt: Date;

  @Column({ name: 'created_by', type: 'uuid', nullable: true })
  createdBy: string | null;

  @Column({ name: 'updated_by', type: 'uuid', nullable: true })
  updatedBy: string | null;
}
