const db = require('../models');
const Users = db.users;

const AnalyticsDaily = db.analytics_daily;

const AnalyticsEvents = db.analytics_events;

const AuditLogs = db.audit_logs;

const Blocks = db.blocks;

const ButtonLinks = db.button_links;

const DomainMappings = db.domain_mappings;

const EmailLogs = db.email_logs;

const FeatureFlags = db.feature_flags;

const Flags = db.flags;

const MediaAssets = db.media_assets;

const PaymentTransactions = db.payment_transactions;

const Plans = db.plans;

const ProfilePages = db.profile_pages;

const SocialLinks = db.social_links;

const Subscriptions = db.subscriptions;

const Templates = db.templates;

const Organizations = db.organizations;

const AnalyticsDailyData = [
  {
    // type code here for "relation_one" field

    date: new Date('2023-10-01'),

    visits: 100,

    clicks: 50,

    top_referrers: '{google.com:50,facebook.com:30}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    date: new Date('2023-10-02'),

    visits: 150,

    clicks: 75,

    top_referrers: '{twitter.com:60,linkedin.com:40}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    date: new Date('2023-10-03'),

    visits: 200,

    clicks: 100,

    top_referrers: '{instagram.com:80,github.com:50}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    date: new Date('2023-10-04'),

    visits: 250,

    clicks: 125,

    top_referrers: '{pinterest.com:90,reddit.com:60}',

    // type code here for "relation_one" field
  },
];

const AnalyticsEventsData = [
  {
    // type code here for "relation_one" field

    event_type: 'VISIT',

    // type code here for "relation_one" field

    referrer: 'https://google.com',

    user_agent: 'Mozilla/5.0',

    ip_hash: 'abc123',

    occurred_at: new Date('2023-10-01T12:00:00Z'),

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    event_type: 'VISIT',

    // type code here for "relation_one" field

    referrer: 'https://facebook.com',

    user_agent: 'Mozilla/5.0',

    ip_hash: 'def456',

    occurred_at: new Date('2023-10-02T12:00:00Z'),

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    event_type: 'CLICK',

    // type code here for "relation_one" field

    referrer: 'https://twitter.com',

    user_agent: 'Mozilla/5.0',

    ip_hash: 'ghi789',

    occurred_at: new Date('2023-10-03T12:00:00Z'),

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    event_type: 'VISIT',

    // type code here for "relation_one" field

    referrer: 'https://linkedin.com',

    user_agent: 'Mozilla/5.0',

    ip_hash: 'jkl012',

    occurred_at: new Date('2023-10-04T12:00:00Z'),

    // type code here for "relation_one" field
  },
];

const AuditLogsData = [
  {
    // type code here for "relation_one" field

    action: 'CREATE',

    target_type: 'ProfilePage',

    target_id: 'johndoe',

    meta: '{description:Created a new profile page.}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    action: 'UPDATE',

    target_type: 'Block',

    target_id: 'janesmith',

    meta: '{description:Updated block content.}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    action: 'DELETE',

    target_type: 'ButtonLink',

    target_id: 'mikejones',

    meta: '{description:Deleted a button link.}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    action: 'CREATE',

    target_type: 'DomainMapping',

    target_id: 'susanlee',

    meta: '{description:Added a new domain mapping.}',

    // type code here for "relation_one" field
  },
];

const BlocksData = [
  {
    // type code here for "relation_one" field

    type: 'SPACER',

    order_index: 0,

    visible: true,

    config: '{title:Welcome to my blog!,subtitle:Tech insights and more.}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    type: 'MAP',

    order_index: 1,

    visible: true,

    config: '{content:Marketing is all about understanding your audience.}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    type: 'SPACER',

    order_index: 2,

    visible: true,

    config: '{imageUrl:https://example.com/images/design1.png}',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    type: 'SOCIALS',

    order_index: 3,

    visible: true,

    config: '{buttons:[{label:Contact Me,url:https://example.com/contact}]}',

    // type code here for "relation_one" field
  },
];

const ButtonLinksData = [
  {
    // type code here for "relation_one" field

    label: 'Contact Me',

    url: 'https://example.com/contact',

    icon: 'mdiEmail',

    enabled: true,

    order_index: 0,

    click_count: 10,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    label: 'GitHub',

    url: 'https://github.com/davidkim',

    icon: 'mdiGithub',

    enabled: true,

    order_index: 1,

    click_count: 25,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    label: 'Subscribe',

    url: 'https://example.com/subscribe',

    icon: 'mdiBell',

    enabled: true,

    order_index: 2,

    click_count: 15,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    label: 'Learn More',

    url: 'https://example.com/learn',

    icon: 'mdiInformation',

    enabled: true,

    order_index: 3,

    click_count: 5,

    // type code here for "relation_one" field
  },
];

const DomainMappingsData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    domain: 'johndoe.com',

    status: 'VERIFYING',

    verification_token: 'abc123',

    ssl_status: 'PENDING',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    domain: 'janesmith.com',

    status: 'VERIFYING',

    verification_token: 'def456',

    ssl_status: 'PENDING',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    domain: 'mikejones.com',

    status: 'ACTIVE',

    verification_token: 'ghi789',

    ssl_status: 'ACTIVE',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    domain: 'susanlee.com',

    status: 'UNVERIFIED',

    verification_token: 'jkl012',

    ssl_status: 'ACTIVE',

    // type code here for "relation_one" field
  },
];

const EmailLogsData = [
  {
    // type code here for "relation_one" field

    type: 'WEEKLY_SUMMARY',

    to_email: 'john.doe@example.com',

    provider_id: 'email_abc123',

    status: 'BOUNCED',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    type: 'WELCOME',

    to_email: 'jane.smith@example.com',

    provider_id: 'email_def456',

    status: 'FAILED',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    type: 'PASSWORD_RESET',

    to_email: 'mike.jones@example.com',

    provider_id: 'email_ghi789',

    status: 'FAILED',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    type: 'PASSWORD_RESET',

    to_email: 'susan.lee@example.com',

    provider_id: 'email_jkl012',

    status: 'SENT',

    // type code here for "relation_one" field
  },
];

const FeatureFlagsData = [
  {
    key: 'new_dashboard',

    value: true,

    // type code here for "relation_one" field
  },

  {
    key: 'beta_feature',

    value: true,

    // type code here for "relation_one" field
  },

  {
    key: 'dark_mode',

    value: true,

    // type code here for "relation_one" field
  },

  {
    key: 'advanced_analytics',

    value: false,

    // type code here for "relation_one" field
  },
];

const FlagsData = [
  {
    // type code here for "relation_one" field

    reason: 'MALWARE',

    status: 'REJECTED',

    notes: 'Reported for copyright infringement.',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    reason: 'OTHER',

    status: 'RESOLVED',

    notes: 'Resolved after review.',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    reason: 'MALWARE',

    status: 'OPEN',

    notes: 'No malware found.',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    reason: 'COPYRIGHT',

    status: 'OPEN',

    notes: 'Under investigation.',

    // type code here for "relation_one" field
  },
];

const MediaAssetsData = [
  {
    // type code here for "relation_one" field

    url: 'https://example.com/media/johndoe1.png',

    type: 'IMAGE',

    width: 800,

    height: 600,

    size_bytes: 204800,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    url: 'https://example.com/media/janesmith1.png',

    type: 'IMAGE',

    width: 400,

    height: 400,

    size_bytes: 102400,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    url: 'https://example.com/media/mikejones1.png',

    type: 'AVATAR',

    width: 1024,

    height: 768,

    size_bytes: 307200,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    url: 'https://example.com/media/susanlee1.png',

    type: 'IMAGE',

    width: 500,

    height: 500,

    size_bytes: 256000,

    // type code here for "relation_one" field
  },
];

const PaymentTransactionsData = [
  {
    // type code here for "relation_one" field

    amount_cents: 0,

    currency: 'USD',

    psp_provider: 'WEP',

    psp_txn_id: 'txn_abc123',

    status: 'REFUNDED',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    amount_cents: 1000,

    currency: 'USD',

    psp_provider: 'WEP',

    psp_txn_id: 'txn_def456',

    status: 'FAILED',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    amount_cents: 5000,

    currency: 'USD',

    psp_provider: 'WEP',

    psp_txn_id: 'txn_ghi789',

    status: 'REFUNDED',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    amount_cents: 10000,

    currency: 'USD',

    psp_provider: 'WOMPI',

    psp_txn_id: 'txn_jkl012',

    status: 'FAILED',

    // type code here for "relation_one" field
  },
];

const PlansData = [
  {
    key: 'FREE',

    name: 'Free',

    price_cents: 0,

    currency: 'USD',

    features:
      '{maxBlocks:6,@customDomain : false,@analytics : true,templates:[modern_flat,neo_brutal]}',

    is_active: true,

    // type code here for "relation_one" field
  },

  {
    key: 'PRO',

    name: 'Pro',

    price_cents: 1000,

    currency: 'USD',

    features:
      '{maxBlocks:50,@customDomain : true,@analytics : true,templates:[modern_flat,neo_brutal,clean_minimal,photo_card]}',

    is_active: true,

    // type code here for "relation_one" field
  },

  {
    key: 'BUSINESS',

    name: 'Business',

    price_cents: 5000,

    currency: 'USD',

    features:
      '{maxBlocks:100,@customDomain : true,@analytics : true,templates:[modern_flat,neo_brutal,clean_minimal,photo_card,vintage_vibe]}',

    is_active: true,

    // type code here for "relation_one" field
  },

  {
    key: 'ENTERPRISE',

    name: 'Enterprise',

    price_cents: 10000,

    currency: 'USD',

    features:
      '{maxBlocks:200,@customDomain : true,@analytics : true,templates:[modern_flat,neo_brutal,clean_minimal,photo_card,vintage_vibe]}',

    is_active: true,

    // type code here for "relation_one" field
  },
];

const ProfilePagesData = [
  {
    // type code here for "relation_one" field

    slug: 'johndoe',

    title: "John's Tech Blog",

    bio: 'Welcome to my tech blog where I share insights on the latest in technology.',

    // type code here for "relation_one" field

    status: 'PUBLISHED',

    published_at: new Date('2023-10-01T12:00:00Z'),

    og_title: "John's Tech Blog",

    og_description: 'Insights on the latest in technology.',

    og_image_url: 'https://example.com/og/johndoe.png',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    slug: 'janesmith',

    title: "Jane's Marketing Tips",

    bio: 'Explore marketing strategies and tips to boost your business.',

    // type code here for "relation_one" field

    status: 'SUSPENDED',

    published_at: new Date('2023-10-02T12:00:00Z'),

    og_title: "Jane's Marketing Tips",

    og_description: 'Marketing strategies and tips.',

    og_image_url: 'https://example.com/og/janesmith.png',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    slug: 'mikejones',

    title: "Mike's Design Portfolio",

    bio: 'Showcasing my latest graphic design projects.',

    // type code here for "relation_one" field

    status: 'SUSPENDED',

    published_at: new Date('2023-10-03T12:00:00Z'),

    og_title: "Mike's Design Portfolio",

    og_description: 'Graphic design projects showcase.',

    og_image_url: 'https://example.com/og/mikejones.png',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    slug: 'susanlee',

    title: "Susan's Startup Advice",

    bio: 'Advice and tips for budding entrepreneurs.',

    // type code here for "relation_one" field

    status: 'SUSPENDED',

    published_at: new Date('2023-10-04T12:00:00Z'),

    og_title: "Susan's Startup Advice",

    og_description: 'Tips for entrepreneurs.',

    og_image_url: 'https://example.com/og/susanlee.png',

    // type code here for "relation_one" field
  },
];

const SocialLinksData = [
  {
    // type code here for "relation_one" field

    network: 'YOUTUBE',

    handle: '@davidkim',

    url: 'https://twitter.com/davidkim',

    order_index: 0,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    network: 'FACEBOOK',

    handle: 'john-doe',

    url: 'https://linkedin.com/in/johndoe',

    order_index: 1,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    network: 'INSTAGRAM',

    handle: '@janesmith',

    url: 'https://instagram.com/janesmith',

    order_index: 2,

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    network: 'FACEBOOK',

    handle: 'mikejones',

    url: 'https://github.com/mikejones',

    order_index: 3,

    // type code here for "relation_one" field
  },
];

const SubscriptionsData = [
  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    status: 'CANCELED',

    trial_ends_at: new Date(Date.now()),

    current_period_start: new Date('2023-10-01T12:00:00Z'),

    current_period_end: new Date('2023-11-01T12:00:00Z'),

    cancel_at_period_end: false,

    psp_customer_id: 'cus_abc123',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    status: 'ACTIVE',

    trial_ends_at: new Date('2023-10-15T12:00:00Z'),

    current_period_start: new Date('2023-10-02T12:00:00Z'),

    current_period_end: new Date('2023-11-02T12:00:00Z'),

    cancel_at_period_end: true,

    psp_customer_id: 'cus_def456',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    status: 'PAST_DUE',

    trial_ends_at: new Date(Date.now()),

    current_period_start: new Date('2023-10-03T12:00:00Z'),

    current_period_end: new Date('2023-11-03T12:00:00Z'),

    cancel_at_period_end: true,

    psp_customer_id: 'cus_ghi789',

    // type code here for "relation_one" field
  },

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    status: 'CANCELED',

    trial_ends_at: new Date(Date.now()),

    current_period_start: new Date('2023-10-04T12:00:00Z'),

    current_period_end: new Date('2023-11-04T12:00:00Z'),

    cancel_at_period_end: false,

    psp_customer_id: 'cus_jkl012',

    // type code here for "relation_one" field
  },
];

const TemplatesData = [
  {
    key: 'modern_flat',

    name: 'Modern Flat',

    variant: 'MODERN',

    colors:
      '{primary:#ffffff,background:#f0f0f0,text:#333333,buttonStyle:flat}',

    is_premium: false,

    // type code here for "relation_one" field
  },

  {
    key: 'neo_brutal',

    name: 'Neo-Brutal',

    variant: 'NEO_BRUTALISM',

    colors:
      '{primary:#000000,background:#ffffff,text:#000000,buttonStyle:brutal}',

    is_premium: true,

    // type code here for "relation_one" field
  },

  {
    key: 'clean_minimal',

    name: 'Clean Minimal',

    variant: 'FLAT',

    colors:
      '{primary:#f5f5f5,background:#ffffff,text:#333333,buttonStyle:minimal}',

    is_premium: true,

    // type code here for "relation_one" field
  },

  {
    key: 'photo_card',

    name: 'Photo Card',

    variant: 'NEO_BRUTALISM',

    colors:
      '{primary:#ffffff,background:#e0e0e0,text:#333333,buttonStyle:card}',

    is_premium: true,

    // type code here for "relation_one" field
  },
];

const OrganizationsData = [
  {
    name: 'Neils Bohr',
  },

  {
    name: 'Ludwig Boltzmann',
  },

  {
    name: 'Ludwig Boltzmann',
  },

  {
    name: 'Theodosius Dobzhansky',
  },
];

// Similar logic for "relation_many"

async function associateUserWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const User0 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (User0?.setOrganization) {
    await User0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const User1 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (User1?.setOrganization) {
    await User1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const User2 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (User2?.setOrganization) {
    await User2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const User3 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (User3?.setOrganization) {
    await User3.setOrganization(relatedOrganization3);
  }
}

async function associateAnalyticsDailyWithProfile_page() {
  const relatedProfile_page0 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const AnalyticsDaily0 = await AnalyticsDaily.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AnalyticsDaily0?.setProfile_page) {
    await AnalyticsDaily0.setProfile_page(relatedProfile_page0);
  }

  const relatedProfile_page1 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const AnalyticsDaily1 = await AnalyticsDaily.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AnalyticsDaily1?.setProfile_page) {
    await AnalyticsDaily1.setProfile_page(relatedProfile_page1);
  }

  const relatedProfile_page2 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const AnalyticsDaily2 = await AnalyticsDaily.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AnalyticsDaily2?.setProfile_page) {
    await AnalyticsDaily2.setProfile_page(relatedProfile_page2);
  }

  const relatedProfile_page3 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const AnalyticsDaily3 = await AnalyticsDaily.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (AnalyticsDaily3?.setProfile_page) {
    await AnalyticsDaily3.setProfile_page(relatedProfile_page3);
  }
}

async function associateAnalyticsDailyWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AnalyticsDaily0 = await AnalyticsDaily.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AnalyticsDaily0?.setOrganization) {
    await AnalyticsDaily0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AnalyticsDaily1 = await AnalyticsDaily.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AnalyticsDaily1?.setOrganization) {
    await AnalyticsDaily1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AnalyticsDaily2 = await AnalyticsDaily.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AnalyticsDaily2?.setOrganization) {
    await AnalyticsDaily2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AnalyticsDaily3 = await AnalyticsDaily.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (AnalyticsDaily3?.setOrganization) {
    await AnalyticsDaily3.setOrganization(relatedOrganization3);
  }
}

async function associateAnalyticsEventWithProfile_page() {
  const relatedProfile_page0 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const AnalyticsEvent0 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AnalyticsEvent0?.setProfile_page) {
    await AnalyticsEvent0.setProfile_page(relatedProfile_page0);
  }

  const relatedProfile_page1 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const AnalyticsEvent1 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AnalyticsEvent1?.setProfile_page) {
    await AnalyticsEvent1.setProfile_page(relatedProfile_page1);
  }

  const relatedProfile_page2 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const AnalyticsEvent2 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AnalyticsEvent2?.setProfile_page) {
    await AnalyticsEvent2.setProfile_page(relatedProfile_page2);
  }

  const relatedProfile_page3 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const AnalyticsEvent3 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (AnalyticsEvent3?.setProfile_page) {
    await AnalyticsEvent3.setProfile_page(relatedProfile_page3);
  }
}

async function associateAnalyticsEventWithLink() {
  const relatedLink0 = await ButtonLinks.findOne({
    offset: Math.floor(Math.random() * (await ButtonLinks.count())),
  });
  const AnalyticsEvent0 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AnalyticsEvent0?.setLink) {
    await AnalyticsEvent0.setLink(relatedLink0);
  }

  const relatedLink1 = await ButtonLinks.findOne({
    offset: Math.floor(Math.random() * (await ButtonLinks.count())),
  });
  const AnalyticsEvent1 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AnalyticsEvent1?.setLink) {
    await AnalyticsEvent1.setLink(relatedLink1);
  }

  const relatedLink2 = await ButtonLinks.findOne({
    offset: Math.floor(Math.random() * (await ButtonLinks.count())),
  });
  const AnalyticsEvent2 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AnalyticsEvent2?.setLink) {
    await AnalyticsEvent2.setLink(relatedLink2);
  }

  const relatedLink3 = await ButtonLinks.findOne({
    offset: Math.floor(Math.random() * (await ButtonLinks.count())),
  });
  const AnalyticsEvent3 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (AnalyticsEvent3?.setLink) {
    await AnalyticsEvent3.setLink(relatedLink3);
  }
}

async function associateAnalyticsEventWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AnalyticsEvent0 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AnalyticsEvent0?.setOrganization) {
    await AnalyticsEvent0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AnalyticsEvent1 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AnalyticsEvent1?.setOrganization) {
    await AnalyticsEvent1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AnalyticsEvent2 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AnalyticsEvent2?.setOrganization) {
    await AnalyticsEvent2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AnalyticsEvent3 = await AnalyticsEvents.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (AnalyticsEvent3?.setOrganization) {
    await AnalyticsEvent3.setOrganization(relatedOrganization3);
  }
}

async function associateAuditLogWithActor_user() {
  const relatedActor_user0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const AuditLog0 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AuditLog0?.setActor_user) {
    await AuditLog0.setActor_user(relatedActor_user0);
  }

  const relatedActor_user1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const AuditLog1 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AuditLog1?.setActor_user) {
    await AuditLog1.setActor_user(relatedActor_user1);
  }

  const relatedActor_user2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const AuditLog2 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AuditLog2?.setActor_user) {
    await AuditLog2.setActor_user(relatedActor_user2);
  }

  const relatedActor_user3 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const AuditLog3 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (AuditLog3?.setActor_user) {
    await AuditLog3.setActor_user(relatedActor_user3);
  }
}

async function associateAuditLogWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AuditLog0 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AuditLog0?.setOrganization) {
    await AuditLog0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AuditLog1 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (AuditLog1?.setOrganization) {
    await AuditLog1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AuditLog2 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (AuditLog2?.setOrganization) {
    await AuditLog2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const AuditLog3 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (AuditLog3?.setOrganization) {
    await AuditLog3.setOrganization(relatedOrganization3);
  }
}

async function associateBlockWithProfile_page() {
  const relatedProfile_page0 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const Block0 = await Blocks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Block0?.setProfile_page) {
    await Block0.setProfile_page(relatedProfile_page0);
  }

  const relatedProfile_page1 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const Block1 = await Blocks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Block1?.setProfile_page) {
    await Block1.setProfile_page(relatedProfile_page1);
  }

  const relatedProfile_page2 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const Block2 = await Blocks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Block2?.setProfile_page) {
    await Block2.setProfile_page(relatedProfile_page2);
  }

  const relatedProfile_page3 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const Block3 = await Blocks.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Block3?.setProfile_page) {
    await Block3.setProfile_page(relatedProfile_page3);
  }
}

async function associateBlockWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Block0 = await Blocks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Block0?.setOrganization) {
    await Block0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Block1 = await Blocks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Block1?.setOrganization) {
    await Block1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Block2 = await Blocks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Block2?.setOrganization) {
    await Block2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Block3 = await Blocks.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Block3?.setOrganization) {
    await Block3.setOrganization(relatedOrganization3);
  }
}

async function associateButtonLinkWithBlock() {
  const relatedBlock0 = await Blocks.findOne({
    offset: Math.floor(Math.random() * (await Blocks.count())),
  });
  const ButtonLink0 = await ButtonLinks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ButtonLink0?.setBlock) {
    await ButtonLink0.setBlock(relatedBlock0);
  }

  const relatedBlock1 = await Blocks.findOne({
    offset: Math.floor(Math.random() * (await Blocks.count())),
  });
  const ButtonLink1 = await ButtonLinks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ButtonLink1?.setBlock) {
    await ButtonLink1.setBlock(relatedBlock1);
  }

  const relatedBlock2 = await Blocks.findOne({
    offset: Math.floor(Math.random() * (await Blocks.count())),
  });
  const ButtonLink2 = await ButtonLinks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ButtonLink2?.setBlock) {
    await ButtonLink2.setBlock(relatedBlock2);
  }

  const relatedBlock3 = await Blocks.findOne({
    offset: Math.floor(Math.random() * (await Blocks.count())),
  });
  const ButtonLink3 = await ButtonLinks.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (ButtonLink3?.setBlock) {
    await ButtonLink3.setBlock(relatedBlock3);
  }
}

async function associateButtonLinkWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const ButtonLink0 = await ButtonLinks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ButtonLink0?.setOrganization) {
    await ButtonLink0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const ButtonLink1 = await ButtonLinks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ButtonLink1?.setOrganization) {
    await ButtonLink1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const ButtonLink2 = await ButtonLinks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ButtonLink2?.setOrganization) {
    await ButtonLink2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const ButtonLink3 = await ButtonLinks.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (ButtonLink3?.setOrganization) {
    await ButtonLink3.setOrganization(relatedOrganization3);
  }
}

async function associateDomainMappingWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const DomainMapping0 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (DomainMapping0?.setUser) {
    await DomainMapping0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const DomainMapping1 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (DomainMapping1?.setUser) {
    await DomainMapping1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const DomainMapping2 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (DomainMapping2?.setUser) {
    await DomainMapping2.setUser(relatedUser2);
  }

  const relatedUser3 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const DomainMapping3 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (DomainMapping3?.setUser) {
    await DomainMapping3.setUser(relatedUser3);
  }
}

async function associateDomainMappingWithProfile_page() {
  const relatedProfile_page0 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const DomainMapping0 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (DomainMapping0?.setProfile_page) {
    await DomainMapping0.setProfile_page(relatedProfile_page0);
  }

  const relatedProfile_page1 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const DomainMapping1 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (DomainMapping1?.setProfile_page) {
    await DomainMapping1.setProfile_page(relatedProfile_page1);
  }

  const relatedProfile_page2 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const DomainMapping2 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (DomainMapping2?.setProfile_page) {
    await DomainMapping2.setProfile_page(relatedProfile_page2);
  }

  const relatedProfile_page3 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const DomainMapping3 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (DomainMapping3?.setProfile_page) {
    await DomainMapping3.setProfile_page(relatedProfile_page3);
  }
}

async function associateDomainMappingWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const DomainMapping0 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (DomainMapping0?.setOrganization) {
    await DomainMapping0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const DomainMapping1 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (DomainMapping1?.setOrganization) {
    await DomainMapping1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const DomainMapping2 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (DomainMapping2?.setOrganization) {
    await DomainMapping2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const DomainMapping3 = await DomainMappings.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (DomainMapping3?.setOrganization) {
    await DomainMapping3.setOrganization(relatedOrganization3);
  }
}

async function associateEmailLogWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const EmailLog0 = await EmailLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (EmailLog0?.setUser) {
    await EmailLog0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const EmailLog1 = await EmailLogs.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (EmailLog1?.setUser) {
    await EmailLog1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const EmailLog2 = await EmailLogs.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (EmailLog2?.setUser) {
    await EmailLog2.setUser(relatedUser2);
  }

  const relatedUser3 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const EmailLog3 = await EmailLogs.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (EmailLog3?.setUser) {
    await EmailLog3.setUser(relatedUser3);
  }
}

async function associateEmailLogWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const EmailLog0 = await EmailLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (EmailLog0?.setOrganization) {
    await EmailLog0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const EmailLog1 = await EmailLogs.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (EmailLog1?.setOrganization) {
    await EmailLog1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const EmailLog2 = await EmailLogs.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (EmailLog2?.setOrganization) {
    await EmailLog2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const EmailLog3 = await EmailLogs.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (EmailLog3?.setOrganization) {
    await EmailLog3.setOrganization(relatedOrganization3);
  }
}

async function associateFeatureFlagWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const FeatureFlag0 = await FeatureFlags.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (FeatureFlag0?.setOrganization) {
    await FeatureFlag0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const FeatureFlag1 = await FeatureFlags.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (FeatureFlag1?.setOrganization) {
    await FeatureFlag1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const FeatureFlag2 = await FeatureFlags.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (FeatureFlag2?.setOrganization) {
    await FeatureFlag2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const FeatureFlag3 = await FeatureFlags.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (FeatureFlag3?.setOrganization) {
    await FeatureFlag3.setOrganization(relatedOrganization3);
  }
}

async function associateFlagWithProfile_page() {
  const relatedProfile_page0 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const Flag0 = await Flags.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Flag0?.setProfile_page) {
    await Flag0.setProfile_page(relatedProfile_page0);
  }

  const relatedProfile_page1 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const Flag1 = await Flags.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Flag1?.setProfile_page) {
    await Flag1.setProfile_page(relatedProfile_page1);
  }

  const relatedProfile_page2 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const Flag2 = await Flags.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Flag2?.setProfile_page) {
    await Flag2.setProfile_page(relatedProfile_page2);
  }

  const relatedProfile_page3 = await ProfilePages.findOne({
    offset: Math.floor(Math.random() * (await ProfilePages.count())),
  });
  const Flag3 = await Flags.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Flag3?.setProfile_page) {
    await Flag3.setProfile_page(relatedProfile_page3);
  }
}

async function associateFlagWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Flag0 = await Flags.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Flag0?.setOrganization) {
    await Flag0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Flag1 = await Flags.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Flag1?.setOrganization) {
    await Flag1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Flag2 = await Flags.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Flag2?.setOrganization) {
    await Flag2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Flag3 = await Flags.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Flag3?.setOrganization) {
    await Flag3.setOrganization(relatedOrganization3);
  }
}

async function associateMediaAssetWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const MediaAsset0 = await MediaAssets.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (MediaAsset0?.setUser) {
    await MediaAsset0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const MediaAsset1 = await MediaAssets.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (MediaAsset1?.setUser) {
    await MediaAsset1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const MediaAsset2 = await MediaAssets.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (MediaAsset2?.setUser) {
    await MediaAsset2.setUser(relatedUser2);
  }

  const relatedUser3 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const MediaAsset3 = await MediaAssets.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (MediaAsset3?.setUser) {
    await MediaAsset3.setUser(relatedUser3);
  }
}

async function associateMediaAssetWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const MediaAsset0 = await MediaAssets.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (MediaAsset0?.setOrganization) {
    await MediaAsset0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const MediaAsset1 = await MediaAssets.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (MediaAsset1?.setOrganization) {
    await MediaAsset1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const MediaAsset2 = await MediaAssets.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (MediaAsset2?.setOrganization) {
    await MediaAsset2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const MediaAsset3 = await MediaAssets.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (MediaAsset3?.setOrganization) {
    await MediaAsset3.setOrganization(relatedOrganization3);
  }
}

async function associatePaymentTransactionWithSubscription() {
  const relatedSubscription0 = await Subscriptions.findOne({
    offset: Math.floor(Math.random() * (await Subscriptions.count())),
  });
  const PaymentTransaction0 = await PaymentTransactions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (PaymentTransaction0?.setSubscription) {
    await PaymentTransaction0.setSubscription(relatedSubscription0);
  }

  const relatedSubscription1 = await Subscriptions.findOne({
    offset: Math.floor(Math.random() * (await Subscriptions.count())),
  });
  const PaymentTransaction1 = await PaymentTransactions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (PaymentTransaction1?.setSubscription) {
    await PaymentTransaction1.setSubscription(relatedSubscription1);
  }

  const relatedSubscription2 = await Subscriptions.findOne({
    offset: Math.floor(Math.random() * (await Subscriptions.count())),
  });
  const PaymentTransaction2 = await PaymentTransactions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (PaymentTransaction2?.setSubscription) {
    await PaymentTransaction2.setSubscription(relatedSubscription2);
  }

  const relatedSubscription3 = await Subscriptions.findOne({
    offset: Math.floor(Math.random() * (await Subscriptions.count())),
  });
  const PaymentTransaction3 = await PaymentTransactions.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (PaymentTransaction3?.setSubscription) {
    await PaymentTransaction3.setSubscription(relatedSubscription3);
  }
}

async function associatePaymentTransactionWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const PaymentTransaction0 = await PaymentTransactions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (PaymentTransaction0?.setOrganization) {
    await PaymentTransaction0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const PaymentTransaction1 = await PaymentTransactions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (PaymentTransaction1?.setOrganization) {
    await PaymentTransaction1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const PaymentTransaction2 = await PaymentTransactions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (PaymentTransaction2?.setOrganization) {
    await PaymentTransaction2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const PaymentTransaction3 = await PaymentTransactions.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (PaymentTransaction3?.setOrganization) {
    await PaymentTransaction3.setOrganization(relatedOrganization3);
  }
}

async function associatePlanWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Plan0 = await Plans.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Plan0?.setOrganization) {
    await Plan0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Plan1 = await Plans.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Plan1?.setOrganization) {
    await Plan1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Plan2 = await Plans.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Plan2?.setOrganization) {
    await Plan2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Plan3 = await Plans.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Plan3?.setOrganization) {
    await Plan3.setOrganization(relatedOrganization3);
  }
}

async function associateProfilePageWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ProfilePage0 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ProfilePage0?.setUser) {
    await ProfilePage0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ProfilePage1 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ProfilePage1?.setUser) {
    await ProfilePage1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ProfilePage2 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ProfilePage2?.setUser) {
    await ProfilePage2.setUser(relatedUser2);
  }

  const relatedUser3 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const ProfilePage3 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (ProfilePage3?.setUser) {
    await ProfilePage3.setUser(relatedUser3);
  }
}

async function associateProfilePageWithTheme_template() {
  const relatedTheme_template0 = await Templates.findOne({
    offset: Math.floor(Math.random() * (await Templates.count())),
  });
  const ProfilePage0 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ProfilePage0?.setTheme_template) {
    await ProfilePage0.setTheme_template(relatedTheme_template0);
  }

  const relatedTheme_template1 = await Templates.findOne({
    offset: Math.floor(Math.random() * (await Templates.count())),
  });
  const ProfilePage1 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ProfilePage1?.setTheme_template) {
    await ProfilePage1.setTheme_template(relatedTheme_template1);
  }

  const relatedTheme_template2 = await Templates.findOne({
    offset: Math.floor(Math.random() * (await Templates.count())),
  });
  const ProfilePage2 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ProfilePage2?.setTheme_template) {
    await ProfilePage2.setTheme_template(relatedTheme_template2);
  }

  const relatedTheme_template3 = await Templates.findOne({
    offset: Math.floor(Math.random() * (await Templates.count())),
  });
  const ProfilePage3 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (ProfilePage3?.setTheme_template) {
    await ProfilePage3.setTheme_template(relatedTheme_template3);
  }
}

async function associateProfilePageWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const ProfilePage0 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ProfilePage0?.setOrganization) {
    await ProfilePage0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const ProfilePage1 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ProfilePage1?.setOrganization) {
    await ProfilePage1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const ProfilePage2 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ProfilePage2?.setOrganization) {
    await ProfilePage2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const ProfilePage3 = await ProfilePages.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (ProfilePage3?.setOrganization) {
    await ProfilePage3.setOrganization(relatedOrganization3);
  }
}

async function associateSocialLinkWithBlock() {
  const relatedBlock0 = await Blocks.findOne({
    offset: Math.floor(Math.random() * (await Blocks.count())),
  });
  const SocialLink0 = await SocialLinks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (SocialLink0?.setBlock) {
    await SocialLink0.setBlock(relatedBlock0);
  }

  const relatedBlock1 = await Blocks.findOne({
    offset: Math.floor(Math.random() * (await Blocks.count())),
  });
  const SocialLink1 = await SocialLinks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (SocialLink1?.setBlock) {
    await SocialLink1.setBlock(relatedBlock1);
  }

  const relatedBlock2 = await Blocks.findOne({
    offset: Math.floor(Math.random() * (await Blocks.count())),
  });
  const SocialLink2 = await SocialLinks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (SocialLink2?.setBlock) {
    await SocialLink2.setBlock(relatedBlock2);
  }

  const relatedBlock3 = await Blocks.findOne({
    offset: Math.floor(Math.random() * (await Blocks.count())),
  });
  const SocialLink3 = await SocialLinks.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (SocialLink3?.setBlock) {
    await SocialLink3.setBlock(relatedBlock3);
  }
}

async function associateSocialLinkWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const SocialLink0 = await SocialLinks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (SocialLink0?.setOrganization) {
    await SocialLink0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const SocialLink1 = await SocialLinks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (SocialLink1?.setOrganization) {
    await SocialLink1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const SocialLink2 = await SocialLinks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (SocialLink2?.setOrganization) {
    await SocialLink2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const SocialLink3 = await SocialLinks.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (SocialLink3?.setOrganization) {
    await SocialLink3.setOrganization(relatedOrganization3);
  }
}

async function associateSubscriptionWithUser() {
  const relatedUser0 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Subscription0 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Subscription0?.setUser) {
    await Subscription0.setUser(relatedUser0);
  }

  const relatedUser1 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Subscription1 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Subscription1?.setUser) {
    await Subscription1.setUser(relatedUser1);
  }

  const relatedUser2 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Subscription2 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Subscription2?.setUser) {
    await Subscription2.setUser(relatedUser2);
  }

  const relatedUser3 = await Users.findOne({
    offset: Math.floor(Math.random() * (await Users.count())),
  });
  const Subscription3 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Subscription3?.setUser) {
    await Subscription3.setUser(relatedUser3);
  }
}

async function associateSubscriptionWithPlan() {
  const relatedPlan0 = await Plans.findOne({
    offset: Math.floor(Math.random() * (await Plans.count())),
  });
  const Subscription0 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Subscription0?.setPlan) {
    await Subscription0.setPlan(relatedPlan0);
  }

  const relatedPlan1 = await Plans.findOne({
    offset: Math.floor(Math.random() * (await Plans.count())),
  });
  const Subscription1 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Subscription1?.setPlan) {
    await Subscription1.setPlan(relatedPlan1);
  }

  const relatedPlan2 = await Plans.findOne({
    offset: Math.floor(Math.random() * (await Plans.count())),
  });
  const Subscription2 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Subscription2?.setPlan) {
    await Subscription2.setPlan(relatedPlan2);
  }

  const relatedPlan3 = await Plans.findOne({
    offset: Math.floor(Math.random() * (await Plans.count())),
  });
  const Subscription3 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Subscription3?.setPlan) {
    await Subscription3.setPlan(relatedPlan3);
  }
}

async function associateSubscriptionWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Subscription0 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Subscription0?.setOrganization) {
    await Subscription0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Subscription1 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Subscription1?.setOrganization) {
    await Subscription1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Subscription2 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Subscription2?.setOrganization) {
    await Subscription2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Subscription3 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Subscription3?.setOrganization) {
    await Subscription3.setOrganization(relatedOrganization3);
  }
}

async function associateTemplateWithOrganization() {
  const relatedOrganization0 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Template0 = await Templates.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Template0?.setOrganization) {
    await Template0.setOrganization(relatedOrganization0);
  }

  const relatedOrganization1 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Template1 = await Templates.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Template1?.setOrganization) {
    await Template1.setOrganization(relatedOrganization1);
  }

  const relatedOrganization2 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Template2 = await Templates.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Template2?.setOrganization) {
    await Template2.setOrganization(relatedOrganization2);
  }

  const relatedOrganization3 = await Organizations.findOne({
    offset: Math.floor(Math.random() * (await Organizations.count())),
  });
  const Template3 = await Templates.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Template3?.setOrganization) {
    await Template3.setOrganization(relatedOrganization3);
  }
}

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await AnalyticsDaily.bulkCreate(AnalyticsDailyData);

    await AnalyticsEvents.bulkCreate(AnalyticsEventsData);

    await AuditLogs.bulkCreate(AuditLogsData);

    await Blocks.bulkCreate(BlocksData);

    await ButtonLinks.bulkCreate(ButtonLinksData);

    await DomainMappings.bulkCreate(DomainMappingsData);

    await EmailLogs.bulkCreate(EmailLogsData);

    await FeatureFlags.bulkCreate(FeatureFlagsData);

    await Flags.bulkCreate(FlagsData);

    await MediaAssets.bulkCreate(MediaAssetsData);

    await PaymentTransactions.bulkCreate(PaymentTransactionsData);

    await Plans.bulkCreate(PlansData);

    await ProfilePages.bulkCreate(ProfilePagesData);

    await SocialLinks.bulkCreate(SocialLinksData);

    await Subscriptions.bulkCreate(SubscriptionsData);

    await Templates.bulkCreate(TemplatesData);

    await Organizations.bulkCreate(OrganizationsData);

    await Promise.all([
      // Similar logic for "relation_many"

      await associateUserWithOrganization(),

      await associateAnalyticsDailyWithProfile_page(),

      await associateAnalyticsDailyWithOrganization(),

      await associateAnalyticsEventWithProfile_page(),

      await associateAnalyticsEventWithLink(),

      await associateAnalyticsEventWithOrganization(),

      await associateAuditLogWithActor_user(),

      await associateAuditLogWithOrganization(),

      await associateBlockWithProfile_page(),

      await associateBlockWithOrganization(),

      await associateButtonLinkWithBlock(),

      await associateButtonLinkWithOrganization(),

      await associateDomainMappingWithUser(),

      await associateDomainMappingWithProfile_page(),

      await associateDomainMappingWithOrganization(),

      await associateEmailLogWithUser(),

      await associateEmailLogWithOrganization(),

      await associateFeatureFlagWithOrganization(),

      await associateFlagWithProfile_page(),

      await associateFlagWithOrganization(),

      await associateMediaAssetWithUser(),

      await associateMediaAssetWithOrganization(),

      await associatePaymentTransactionWithSubscription(),

      await associatePaymentTransactionWithOrganization(),

      await associatePlanWithOrganization(),

      await associateProfilePageWithUser(),

      await associateProfilePageWithTheme_template(),

      await associateProfilePageWithOrganization(),

      await associateSocialLinkWithBlock(),

      await associateSocialLinkWithOrganization(),

      await associateSubscriptionWithUser(),

      await associateSubscriptionWithPlan(),

      await associateSubscriptionWithOrganization(),

      await associateTemplateWithOrganization(),
    ]);
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.bulkDelete('analytics_daily', null, {});

    await queryInterface.bulkDelete('analytics_events', null, {});

    await queryInterface.bulkDelete('audit_logs', null, {});

    await queryInterface.bulkDelete('blocks', null, {});

    await queryInterface.bulkDelete('button_links', null, {});

    await queryInterface.bulkDelete('domain_mappings', null, {});

    await queryInterface.bulkDelete('email_logs', null, {});

    await queryInterface.bulkDelete('feature_flags', null, {});

    await queryInterface.bulkDelete('flags', null, {});

    await queryInterface.bulkDelete('media_assets', null, {});

    await queryInterface.bulkDelete('payment_transactions', null, {});

    await queryInterface.bulkDelete('plans', null, {});

    await queryInterface.bulkDelete('profile_pages', null, {});

    await queryInterface.bulkDelete('social_links', null, {});

    await queryInterface.bulkDelete('subscriptions', null, {});

    await queryInterface.bulkDelete('templates', null, {});

    await queryInterface.bulkDelete('organizations', null, {});
  },
};
