require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const tokenRoute = require("./routes/token.route.js");
const tradingRoute = require("./routes/trading.route.js");
const logoRoute = require("./routes/logo.route.js");
const userRoute = require("./routes/user.route.js");
const UTokenRoute = require("./routes/userToken.route.js");
const botRoutes = require("./routes/bot.route.js");
const threadRoutes = require("./routes/thread.bot.route.js");
const twitterRoutes = require("./routes/twitterss.route.js");
const bannerRoutes = require("./routes/banner.route.js");
const commentRoutes = require("./routes/comment.route.js");

const cors = require("cors");

const app = express();

app.use(
  cors({
    origin: [
      "http://localhost:3000",
      "http://localhost:3001",
      "https://nft.softrobo.systems",
    ],
    methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
    credentials: true,
  })
);

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use("/images", express.static("images"));

// Starting of Token Api
app.use("/api/tokens", tokenRoute);
app.use("/api/trading", tradingRoute);
app.use("/api/logo", logoRoute);
app.use("/api/token", UTokenRoute);
app.use("/api/bot", botRoutes);
app.use("/api/chat", threadRoutes);
app.use("/api/chat", threadRoutes);
app.use("/api/twitter", twitterRoutes);
app.use("/api/banner", bannerRoutes);
app.use("/api/comment", commentRoutes);
// Starting of Token Api
app.use("/api/user", userRoute);

// Starting of Api
app.get("/", (req, res) => {
  res.send("Welcome to the Token api");
});

// Port Connection
app.listen(4000, (req, res) => {
  console.log("Server is running on port 4000");
});

// Connect Mongose Database
mongoose
  .connect(
    "mongodb+srv://softrobo:anytime@crypto.iwkew.mongodb.net/?retryWrites=true&w=majority&appName=Crypto"
  )
  .then(() => console.log("Database Connected Successfully"));
