import { connectDB } from "../server/utils/mongoose.js";
import Event from "../server/models/event.js";

async function seedSeriesEvents() {
  try {
    await connectDB();
    console.log("Connected to database");

    // Generate future dates relative to today
    const today = new Date();

    // Workshop Series: "Cooperative Game Development Fundamentals"
    const workshopSeries = [
      {
        title: "Cooperative Business Models in Game Development",
        slug: "coop-business-models-workshop",
        tagline: "Learn the foundations of cooperative business structures",
        description:
          "An introductory workshop covering the basic principles and structures of worker cooperatives in the game development industry.",
        content:
          "This workshop will cover the legal structures, governance models, and financial frameworks that make cooperative game studios successful.",
        startDate: new Date(
          today.getFullYear(),
          today.getMonth(),
          today.getDate() + 15,
          19,
          0,
        ),
        endDate: new Date(
          today.getFullYear(),
          today.getMonth(),
          today.getDate() + 15,
          21,
          0,
        ),
        eventType: "workshop",
        location: "#workshop-fundamentals",
        isOnline: true,
        membersOnly: false,
        registrationRequired: true,
        maxAttendees: 50,
        series: {
          id: "coop-dev-fundamentals",
          title: "Cooperative Game Development Fundamentals",
          description:
            "A comprehensive workshop series covering the essentials of building and running cooperative game studios",
          type: "workshop_series",
          position: 1,
          totalEvents: 4,
          isSeriesEvent: true,
        },
        createdBy: "admin",
      },
      {
        title: "Democratic Decision Making in Creative Projects",
        slug: "democratic-decision-making-workshop",
        tagline: "Practical tools for collaborative project management",
        description:
          "Learn how to implement democratic decision-making processes that work for creative teams and game development projects.",
        content:
          "This workshop focuses on consensus building, conflict resolution, and collaborative project management techniques.",
        startDate: new Date("2024-10-22T19:00:00.000Z"),
        endDate: new Date("2024-10-22T21:00:00.000Z"),
        eventType: "workshop",
        location: "#workshop-fundamentals",
        isOnline: true,
        membersOnly: false,
        registrationRequired: true,
        maxAttendees: 50,
        series: {
          id: "coop-dev-fundamentals",
          title: "Cooperative Game Development Fundamentals",
          description:
            "A comprehensive workshop series covering the essentials of building and running cooperative game studios",
          type: "workshop_series",
          position: 2,
          totalEvents: 4,
          isSeriesEvent: true,
        },
        createdBy: "admin",
      },
      {
        title: "Funding and Financial Models for Co-ops",
        slug: "coop-funding-workshop",
        tagline: "Sustainable financing for cooperative studios",
        description:
          "Explore funding options, revenue sharing models, and financial management strategies specific to cooperative game studios.",
        content:
          "This workshop covers grant opportunities, crowdfunding strategies, and internal financial management for worker cooperatives.",
        startDate: new Date("2024-10-29T19:00:00.000Z"),
        endDate: new Date("2024-10-29T21:00:00.000Z"),
        eventType: "workshop",
        location: "#workshop-fundamentals",
        isOnline: true,
        membersOnly: false,
        registrationRequired: true,
        maxAttendees: 50,
        series: {
          id: "coop-dev-fundamentals",
          title: "Cooperative Game Development Fundamentals",
          description:
            "A comprehensive workshop series covering the essentials of building and running cooperative game studios",
          type: "workshop_series",
          position: 3,
          totalEvents: 4,
          isSeriesEvent: true,
        },
        createdBy: "admin",
      },
      {
        title: "Building Your Cooperative Studio",
        slug: "building-coop-studio-workshop",
        tagline: "From concept to reality: launching your co-op",
        description:
          "A practical guide to forming a cooperative game studio, covering legal formation, member recruitment, and launch strategies.",
        content:
          "This final workshop in the series provides a step-by-step guide to actually forming and launching a cooperative game studio.",
        startDate: new Date("2024-11-05T19:00:00.000Z"),
        endDate: new Date("2024-11-05T21:00:00.000Z"),
        eventType: "workshop",
        location: "#workshop-fundamentals",
        isOnline: true,
        membersOnly: false,
        registrationRequired: true,
        maxAttendees: 50,
        series: {
          id: "coop-dev-fundamentals",
          title: "Cooperative Game Development Fundamentals",
          description:
            "A comprehensive workshop series covering the essentials of building and running cooperative game studios",
          type: "workshop_series",
          position: 4,
          totalEvents: 4,
          isSeriesEvent: true,
        },
        createdBy: "admin",
      },
    ];

    // Monthly Community Meetup Series
    const meetupSeries = [
      {
        title: "October Community Meetup",
        slug: "october-community-meetup",
        tagline: "Monthly gathering for cooperative game developers",
        description:
          "Join fellow cooperative game developers for informal networking, project sharing, and community building.",
        content:
          "Our monthly community meetup provides a relaxed environment to share your projects, get feedback, and connect with other developers interested in cooperative models.",
        startDate: new Date("2024-10-12T18:00:00.000Z"),
        endDate: new Date("2024-10-12T20:00:00.000Z"),
        eventType: "community",
        location: "#community-meetup",
        isOnline: true,
        membersOnly: false,
        registrationRequired: false,
        series: {
          id: "monthly-meetups",
          title: "Monthly Community Meetups",
          description:
            "Regular monthly gatherings for the cooperative game development community",
          type: "recurring_meetup",
          position: 1,
          totalEvents: 12,
          isSeriesEvent: true,
        },
        createdBy: "admin",
      },
      {
        title: "November Community Meetup",
        slug: "november-community-meetup",
        tagline: "Monthly gathering for cooperative game developers",
        description:
          "Join fellow cooperative game developers for informal networking, project sharing, and community building.",
        content:
          "Our monthly community meetup provides a relaxed environment to share your projects, get feedback, and connect with other developers interested in cooperative models.",
        startDate: new Date("2024-11-09T18:00:00.000Z"),
        endDate: new Date("2024-11-09T20:00:00.000Z"),
        eventType: "community",
        location: "#community-meetup",
        isOnline: true,
        membersOnly: false,
        registrationRequired: false,
        series: {
          id: "monthly-meetups",
          title: "Monthly Community Meetups",
          description:
            "Regular monthly gatherings for the cooperative game development community",
          type: "recurring_meetup",
          position: 2,
          totalEvents: 12,
          isSeriesEvent: true,
        },
        createdBy: "admin",
      },
    ];

    // Insert all series events
    const allSeriesEvents = [...workshopSeries, ...meetupSeries];

    for (const eventData of allSeriesEvents) {
      const existingEvent = await Event.findOne({ slug: eventData.slug });
      if (!existingEvent) {
        const event = new Event(eventData);
        await event.save();
        console.log(`Created series event: ${event.title}`);
      } else {
        console.log(`Series event already exists: ${eventData.title}`);
      }
    }

    console.log("Series events seeding completed!");
    process.exit(0);
  } catch (error) {
    console.error("Error seeding series events:", error);
    process.exit(1);
  }
}

seedSeriesEvents();
