import "reflect-metadata"
import { DataSource } from "typeorm"
import process from 'node:process'

// 实体类导入
import { UserEntity as User } from "./modules/users/user.entity"
import { Role } from "./modules/users/role.entity"
import { ClassroomData } from "./modules/classroom/classroom-data.entity"
import { DateNotes } from "./modules/stock/date-notes.entity"
import { StockData } from "./modules/stock/stock-data.entity"
import { StockXunlianCodes } from "./modules/stock/stock-xunlian-codes.entity"
import { SubmissionRecords } from "./modules/submission/submission-records.entity"
import { File } from "./modules/files/file.entity"
import { ChatMessage } from "./modules/chat/chat-message.entity"
import { VodVideo } from "./modules/vod/vod-video.entity"

export const AppDataSource = new DataSource({
  type: "mysql",
  host: process.env.DB_HOST || "localhost",
  port: parseInt(process.env.DB_PORT || "3306"),
  username: process.env.DB_USERNAME || "root",
  password: process.env.DB_PASSWORD || "",
  database: process.env.DB_DATABASE || "d8dai",
  entities: [
    User, Role, File, ClassroomData, DateNotes, StockData, StockXunlianCodes, SubmissionRecords, ChatMessage, VodVideo
  ],
  migrations: [],
  synchronize: process.env.DB_SYNCHRONIZE !== "false",
  logging: process.env.DB_LOGGING === "true",
});