import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { User } from '../../user/user.entity';

@Entity('feishu_bots')
export class FeishuBot {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'user_id' })
  userId: string;

  @ManyToOne(() => User, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'user_id' })
  user: User;

  @Column({ name: 'app_id', length: 64 })
  appId: string;

  @Column({ name: 'app_secret', length: 256 })
  appSecret: string;

  @Column({ name: 'tenant_access_token', nullable: true, type: 'text' })
  tenantAccessToken: string;

  @Column({ name: 'token_expires_at', nullable: true, type: 'datetime' })
  tokenExpiresAt: Date;

  @Column({ name: 'verification_token', nullable: true, length: 128 })
  verificationToken: string;

  @Column({ name: 'encrypt_key', nullable: true, length: 256 })
  encryptKey: string;

  @Column({ name: 'bot_name', nullable: true, length: 128 })
  botName: string;

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

  @Column({ name: 'is_default', default: false })
  isDefault: boolean;

  @Column({ name: 'webhook_url', nullable: true, type: 'text' })
  webhookUrl: string;

  @Column({ name: 'use_web_socket', default: false })
  useWebSocket: boolean;

  @Column({ name: 'ws_connection_state', nullable: true, length: 32 })
  wsConnectionState: string;

  @Column({ name: 'knowledge_base_id', nullable: true, length: 36 })
  knowledgeBaseId: string;

  @Column({ name: 'knowledge_group_id', nullable: true, length: 36 })
  knowledgeGroupId: string;

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

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