import mongoose from "mongoose"; // 导入 mongoose 和 Connection 用于处理远程连接
import Art, { IArt } from "../../src/models/artModel"; // 👈 导入 Art 模型和 IArt 接口

// 远程数据库连接 URL
const REMOTE_MONGO_URI = "mongodb://coloring:coloring123.@hk.jccytech.cn:7881/coloring_ol?authSource=admin";

async function test() {
  let remoteConn = null;

  try {
    // 建立远程数据库连接和模型
    remoteConn = await mongoose.createConnection(REMOTE_MONGO_URI);
    const RemoteArt = remoteConn.model<IArt>("Art", Art.schema);
    console.log(`Connected to remote database.`);

    const remoteArtDoc = await RemoteArt.findById("627b856e13d2c95a09ff2cf5");
    if (remoteArtDoc) {
      remoteArtDoc.totalStartCount = 1;
      remoteArtDoc.totalDoneCount = 1;
      remoteArtDoc.completionRate = 100;
      await remoteArtDoc.save();
      console.log(remoteArtDoc);
    } else {
      console.warn(`Remote Art document with ID 62aecb352d374651fce80992 not found. Skipping remote update.`);
    }
  } catch (error) {
    console.error(error);
  } finally {
    if (remoteConn) {
      await remoteConn.close();
      console.log("Disconnected from remote database.");
    }
  }
}

test();
