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

@Entity('agent_instances')
export class AgentInstance {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ type: 'uuid', name: 'user_id' })
  userId!: string;

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

  @Column({ type: 'varchar', length: 50, name: 'agent_type', default: 'openclaw' })
  agentType!: string;

  @Column({ type: 'uuid', name: 'pool_server_id', nullable: true })
  poolServerId?: string;

  @Column({ type: 'varchar', length: 255, name: 'server_host', nullable: true })
  serverHost?: string;

  @Column({ type: 'int', name: 'ssh_port', default: 22 })
  sshPort!: number;

  @Column({ type: 'varchar', length: 100, name: 'ssh_user', nullable: true })
  sshUser?: string;

  @Column({ type: 'varchar', length: 150, name: 'container_name', unique: true })
  containerName!: string;

  @Column({ type: 'int', name: 'host_port' })
  hostPort!: number;

  @Column({ type: 'varchar', length: 20, default: 'deploying' })
  status!: 'deploying' | 'running' | 'stopped' | 'error' | 'removed';

  @Column({ type: 'text', name: 'error_message', nullable: true })
  errorMessage?: string;

  @Column({ type: 'text', name: 'openclaw_token', nullable: true })
  openclawToken?: string;

  @Column({ type: 'text', name: 'openclaw_token_iv', nullable: true })
  openclawTokenIv?: string;

  @Column({ type: 'jsonb', default: {} })
  config!: Record<string, unknown>;

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

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