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

const Assets = db.assets;

const Employees = db.employees;

const FinancialRecords = db.financial_records;

const Inventories = db.inventories;

const ManufacturingOrders = db.manufacturing_orders;

const Procurements = db.procurements;

const Projects = db.projects;

const Sales = db.sales;

const Subscriptions = db.subscriptions;

const Invoices = db.invoices;

const Payments = db.payments;

const Contracts = db.contracts;

const Shipments = db.shipments;

const Warehouses = db.warehouses;

const Payrolls = db.payrolls;

const Attendance = db.attendance;

const LeaveRequests = db.leave_requests;

const Recruitment = db.recruitment;

const Budgets = db.budgets;

const Taxes = db.taxes;

const Expenses = db.expenses;

const Revenues = db.revenues;

const Leads = db.leads;

const Tickets = db.tickets;

const MarketingCampaigns = db.marketing_campaigns;

const AuditLogs = db.audit_logs;

const Notifications = db.notifications;

const Companies = db.companies;

const AssetsData = [
  {
    asset_name: 'Company Car',

    value: 20000,

    // type code here for "relation_one" field

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

  {
    asset_name: 'Office Building',

    value: 500000,

    // type code here for "relation_one" field

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

  {
    asset_name: 'Machinery',

    value: 150000,

    // type code here for "relation_one" field

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

  {
    asset_name: 'Furniture',

    value: 30000,

    // type code here for "relation_one" field

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

  {
    asset_name: 'Computers',

    value: 10000,

    // type code here for "relation_one" field

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

const EmployeesData = [
  {
    full_name: 'Alice Johnson',

    // type code here for "relation_one" field

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

  {
    full_name: 'Bob Smith',

    // type code here for "relation_one" field

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

  {
    full_name: 'Charlie Brown',

    // type code here for "relation_one" field

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

  {
    full_name: 'Diana Prince',

    // type code here for "relation_one" field

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

  {
    full_name: 'Ethan Hunt',

    // type code here for "relation_one" field

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

const FinancialRecordsData = [
  {
    record_type: 'Invoice',

    amount: 1500,

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

    // type code here for "relation_one" field

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

  {
    record_type: 'Expense',

    amount: 300,

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

    // type code here for "relation_one" field

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

  {
    record_type: 'Revenue',

    amount: 5000,

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

    // type code here for "relation_one" field

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

  {
    record_type: 'Invoice',

    amount: 2500,

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

    // type code here for "relation_one" field

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

  {
    record_type: 'Expense',

    amount: 700,

    date: new Date('2023-10-05T14:00:00Z'),

    // type code here for "relation_one" field

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

const InventoriesData = [
  {
    item_name: 'Laptop',

    quantity: 50,

    // type code here for "relation_one" field

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

  {
    item_name: 'Printer',

    quantity: 20,

    // type code here for "relation_one" field

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

  {
    item_name: 'Desk Chair',

    quantity: 100,

    // type code here for "relation_one" field

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

  {
    item_name: 'Monitor',

    quantity: 75,

    // type code here for "relation_one" field

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

  {
    item_name: 'Keyboard',

    quantity: 150,

    // type code here for "relation_one" field

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

const ManufacturingOrdersData = [
  {
    order_name: 'Order 001',

    scheduled_date: new Date('2023-10-10T09:00:00Z'),

    // type code here for "relation_one" field

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

  {
    order_name: 'Order 002',

    scheduled_date: new Date('2023-10-11T10:00:00Z'),

    // type code here for "relation_one" field

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

  {
    order_name: 'Order 003',

    scheduled_date: new Date('2023-10-12T11:00:00Z'),

    // type code here for "relation_one" field

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

  {
    order_name: 'Order 004',

    scheduled_date: new Date('2023-10-13T12:00:00Z'),

    // type code here for "relation_one" field

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

  {
    order_name: 'Order 005',

    scheduled_date: new Date('2023-10-14T13:00:00Z'),

    // type code here for "relation_one" field

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

const ProcurementsData = [
  {
    request_name: 'Office Supplies',

    approval_status: 'Approved',

    // type code here for "relation_one" field

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

  {
    request_name: 'IT Equipment',

    approval_status: 'Approved',

    // type code here for "relation_one" field

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

  {
    request_name: 'Raw Materials',

    approval_status: 'Pending',

    // type code here for "relation_one" field

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

  {
    request_name: 'Marketing Materials',

    approval_status: 'Approved',

    // type code here for "relation_one" field

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

  {
    request_name: 'Safety Gear',

    approval_status: 'Approved',

    // type code here for "relation_one" field

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

const ProjectsData = [
  {
    project_name: 'Project Alpha',

    start_date: new Date('2023-10-01T08:00:00Z'),

    end_date: new Date('2023-12-01T17:00:00Z'),

    // type code here for "relation_one" field

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

  {
    project_name: 'Project Beta',

    start_date: new Date('2023-10-05T09:00:00Z'),

    end_date: new Date('2023-11-05T17:00:00Z'),

    // type code here for "relation_one" field

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

  {
    project_name: 'Project Gamma',

    start_date: new Date('2023-10-10T10:00:00Z'),

    end_date: new Date('2023-12-10T17:00:00Z'),

    // type code here for "relation_one" field

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

  {
    project_name: 'Project Delta',

    start_date: new Date('2023-10-15T11:00:00Z'),

    end_date: new Date('2023-11-15T17:00:00Z'),

    // type code here for "relation_one" field

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

  {
    project_name: 'Project Epsilon',

    start_date: new Date('2023-10-20T12:00:00Z'),

    end_date: new Date('2023-12-20T17:00:00Z'),

    // type code here for "relation_one" field

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

const SalesData = [
  {
    lead_name: 'Acme Corp',

    status: 'Closed',

    // type code here for "relation_one" field

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

  {
    lead_name: 'Beta Industries',

    status: 'Closed',

    // type code here for "relation_one" field

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

  {
    lead_name: 'Gamma Enterprises',

    status: 'InProgress',

    // type code here for "relation_one" field

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

  {
    lead_name: 'Delta Co',

    status: 'New',

    // type code here for "relation_one" field

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

  {
    lead_name: 'Epsilon Ltd',

    status: 'New',

    // type code here for "relation_one" field

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

const SubscriptionsData = [
  {
    subscription_name: 'Basic Plan',

    renewal_date: new Date('2023-11-01T00:00:00Z'),

    // type code here for "relation_one" field

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

  {
    subscription_name: 'Standard Plan',

    renewal_date: new Date('2023-11-05T00:00:00Z'),

    // type code here for "relation_one" field

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

  {
    subscription_name: 'Premium Plan',

    renewal_date: new Date('2023-11-10T00:00:00Z'),

    // type code here for "relation_one" field

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

  {
    subscription_name: 'Enterprise Plan',

    renewal_date: new Date('2023-11-15T00:00:00Z'),

    // type code here for "relation_one" field

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

  {
    subscription_name: 'Custom Plan',

    renewal_date: new Date('2023-11-20T00:00:00Z'),

    // type code here for "relation_one" field

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

const InvoicesData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const PaymentsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const ContractsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const ShipmentsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const WarehousesData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const PayrollsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const AttendanceData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const LeaveRequestsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const RecruitmentData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const BudgetsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const TaxesData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const ExpensesData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const RevenuesData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const LeadsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const TicketsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const MarketingCampaignsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

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

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

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

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

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

const NotificationsData = [
  {
    // type code here for "relation_one" field
  },

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

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

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

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

const CompaniesData = [
  {
    name: 'Tech Innovators',
  },

  {
    name: 'Green Solutions',
  },

  {
    name: 'Finance Experts',
  },

  {
    name: 'Retail Giants',
  },

  {
    name: 'Manufacturing Hub',
  },
];

// Similar logic for "relation_many"

async function associateUserWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const User0 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (User0?.setCompany) {
    await User0.setCompany(relatedCompany0);
  }

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

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

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

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const User4 = await Users.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (User4?.setCompany) {
    await User4.setCompany(relatedCompany4);
  }
}

async function associateAssetWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset0 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Asset0?.setCompany) {
    await Asset0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset1 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Asset1?.setCompany) {
    await Asset1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset2 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Asset2?.setCompany) {
    await Asset2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset3 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Asset3?.setCompany) {
    await Asset3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset4 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Asset4?.setCompany) {
    await Asset4.setCompany(relatedCompany4);
  }
}

async function associateAssetWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset0 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Asset0?.setCompany) {
    await Asset0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset1 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Asset1?.setCompany) {
    await Asset1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset2 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Asset2?.setCompany) {
    await Asset2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset3 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Asset3?.setCompany) {
    await Asset3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Asset4 = await Assets.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Asset4?.setCompany) {
    await Asset4.setCompany(relatedCompany4);
  }
}

async function associateEmployeeWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee0 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Employee0?.setCompany) {
    await Employee0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee1 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Employee1?.setCompany) {
    await Employee1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee2 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Employee2?.setCompany) {
    await Employee2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee3 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Employee3?.setCompany) {
    await Employee3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee4 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Employee4?.setCompany) {
    await Employee4.setCompany(relatedCompany4);
  }
}

async function associateEmployeeWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee0 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Employee0?.setCompany) {
    await Employee0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee1 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Employee1?.setCompany) {
    await Employee1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee2 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Employee2?.setCompany) {
    await Employee2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee3 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Employee3?.setCompany) {
    await Employee3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Employee4 = await Employees.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Employee4?.setCompany) {
    await Employee4.setCompany(relatedCompany4);
  }
}

async function associateFinancialRecordWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord0 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (FinancialRecord0?.setCompany) {
    await FinancialRecord0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord1 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (FinancialRecord1?.setCompany) {
    await FinancialRecord1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord2 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (FinancialRecord2?.setCompany) {
    await FinancialRecord2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord3 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (FinancialRecord3?.setCompany) {
    await FinancialRecord3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord4 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (FinancialRecord4?.setCompany) {
    await FinancialRecord4.setCompany(relatedCompany4);
  }
}

async function associateFinancialRecordWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord0 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (FinancialRecord0?.setCompany) {
    await FinancialRecord0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord1 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (FinancialRecord1?.setCompany) {
    await FinancialRecord1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord2 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (FinancialRecord2?.setCompany) {
    await FinancialRecord2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord3 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (FinancialRecord3?.setCompany) {
    await FinancialRecord3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const FinancialRecord4 = await FinancialRecords.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (FinancialRecord4?.setCompany) {
    await FinancialRecord4.setCompany(relatedCompany4);
  }
}

async function associateInventoryWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory0 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Inventory0?.setCompany) {
    await Inventory0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory1 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Inventory1?.setCompany) {
    await Inventory1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory2 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Inventory2?.setCompany) {
    await Inventory2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory3 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Inventory3?.setCompany) {
    await Inventory3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory4 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Inventory4?.setCompany) {
    await Inventory4.setCompany(relatedCompany4);
  }
}

async function associateInventoryWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory0 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Inventory0?.setCompany) {
    await Inventory0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory1 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Inventory1?.setCompany) {
    await Inventory1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory2 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Inventory2?.setCompany) {
    await Inventory2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory3 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Inventory3?.setCompany) {
    await Inventory3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Inventory4 = await Inventories.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Inventory4?.setCompany) {
    await Inventory4.setCompany(relatedCompany4);
  }
}

async function associateManufacturingOrderWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder0 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ManufacturingOrder0?.setCompany) {
    await ManufacturingOrder0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder1 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ManufacturingOrder1?.setCompany) {
    await ManufacturingOrder1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder2 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ManufacturingOrder2?.setCompany) {
    await ManufacturingOrder2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder3 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (ManufacturingOrder3?.setCompany) {
    await ManufacturingOrder3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder4 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (ManufacturingOrder4?.setCompany) {
    await ManufacturingOrder4.setCompany(relatedCompany4);
  }
}

async function associateManufacturingOrderWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder0 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (ManufacturingOrder0?.setCompany) {
    await ManufacturingOrder0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder1 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (ManufacturingOrder1?.setCompany) {
    await ManufacturingOrder1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder2 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (ManufacturingOrder2?.setCompany) {
    await ManufacturingOrder2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder3 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (ManufacturingOrder3?.setCompany) {
    await ManufacturingOrder3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const ManufacturingOrder4 = await ManufacturingOrders.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (ManufacturingOrder4?.setCompany) {
    await ManufacturingOrder4.setCompany(relatedCompany4);
  }
}

async function associateProcurementWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement0 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Procurement0?.setCompany) {
    await Procurement0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement1 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Procurement1?.setCompany) {
    await Procurement1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement2 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Procurement2?.setCompany) {
    await Procurement2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement3 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Procurement3?.setCompany) {
    await Procurement3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement4 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Procurement4?.setCompany) {
    await Procurement4.setCompany(relatedCompany4);
  }
}

async function associateProcurementWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement0 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Procurement0?.setCompany) {
    await Procurement0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement1 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Procurement1?.setCompany) {
    await Procurement1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement2 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Procurement2?.setCompany) {
    await Procurement2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement3 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Procurement3?.setCompany) {
    await Procurement3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Procurement4 = await Procurements.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Procurement4?.setCompany) {
    await Procurement4.setCompany(relatedCompany4);
  }
}

async function associateProjectWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project0 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Project0?.setCompany) {
    await Project0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project1 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Project1?.setCompany) {
    await Project1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project2 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Project2?.setCompany) {
    await Project2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project3 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Project3?.setCompany) {
    await Project3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project4 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Project4?.setCompany) {
    await Project4.setCompany(relatedCompany4);
  }
}

async function associateProjectWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project0 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Project0?.setCompany) {
    await Project0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project1 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Project1?.setCompany) {
    await Project1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project2 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Project2?.setCompany) {
    await Project2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project3 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Project3?.setCompany) {
    await Project3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Project4 = await Projects.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Project4?.setCompany) {
    await Project4.setCompany(relatedCompany4);
  }
}

async function associateSaleWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale0 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Sale0?.setCompany) {
    await Sale0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale1 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Sale1?.setCompany) {
    await Sale1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale2 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Sale2?.setCompany) {
    await Sale2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale3 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Sale3?.setCompany) {
    await Sale3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale4 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Sale4?.setCompany) {
    await Sale4.setCompany(relatedCompany4);
  }
}

async function associateSaleWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale0 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Sale0?.setCompany) {
    await Sale0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale1 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Sale1?.setCompany) {
    await Sale1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale2 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Sale2?.setCompany) {
    await Sale2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale3 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Sale3?.setCompany) {
    await Sale3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Sale4 = await Sales.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Sale4?.setCompany) {
    await Sale4.setCompany(relatedCompany4);
  }
}

async function associateSubscriptionWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Subscription0 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Subscription0?.setCompany) {
    await Subscription0.setCompany(relatedCompany0);
  }

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

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

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

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Subscription4 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Subscription4?.setCompany) {
    await Subscription4.setCompany(relatedCompany4);
  }
}

async function associateSubscriptionWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Subscription0 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Subscription0?.setCompany) {
    await Subscription0.setCompany(relatedCompany0);
  }

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

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

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

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Subscription4 = await Subscriptions.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Subscription4?.setCompany) {
    await Subscription4.setCompany(relatedCompany4);
  }
}

async function associateInvoiceWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Invoice0 = await Invoices.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Invoice0?.setCompany) {
    await Invoice0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Invoice1 = await Invoices.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Invoice1?.setCompany) {
    await Invoice1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Invoice2 = await Invoices.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Invoice2?.setCompany) {
    await Invoice2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Invoice3 = await Invoices.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Invoice3?.setCompany) {
    await Invoice3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Invoice4 = await Invoices.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Invoice4?.setCompany) {
    await Invoice4.setCompany(relatedCompany4);
  }
}

async function associatePaymentWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payment0 = await Payments.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Payment0?.setCompany) {
    await Payment0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payment1 = await Payments.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Payment1?.setCompany) {
    await Payment1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payment2 = await Payments.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Payment2?.setCompany) {
    await Payment2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payment3 = await Payments.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Payment3?.setCompany) {
    await Payment3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payment4 = await Payments.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Payment4?.setCompany) {
    await Payment4.setCompany(relatedCompany4);
  }
}

async function associateContractWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Contract0 = await Contracts.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Contract0?.setCompany) {
    await Contract0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Contract1 = await Contracts.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Contract1?.setCompany) {
    await Contract1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Contract2 = await Contracts.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Contract2?.setCompany) {
    await Contract2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Contract3 = await Contracts.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Contract3?.setCompany) {
    await Contract3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Contract4 = await Contracts.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Contract4?.setCompany) {
    await Contract4.setCompany(relatedCompany4);
  }
}

async function associateShipmentWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Shipment0 = await Shipments.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Shipment0?.setCompany) {
    await Shipment0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Shipment1 = await Shipments.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Shipment1?.setCompany) {
    await Shipment1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Shipment2 = await Shipments.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Shipment2?.setCompany) {
    await Shipment2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Shipment3 = await Shipments.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Shipment3?.setCompany) {
    await Shipment3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Shipment4 = await Shipments.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Shipment4?.setCompany) {
    await Shipment4.setCompany(relatedCompany4);
  }
}

async function associateWarehouseWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Warehouse0 = await Warehouses.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Warehouse0?.setCompany) {
    await Warehouse0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Warehouse1 = await Warehouses.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Warehouse1?.setCompany) {
    await Warehouse1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Warehouse2 = await Warehouses.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Warehouse2?.setCompany) {
    await Warehouse2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Warehouse3 = await Warehouses.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Warehouse3?.setCompany) {
    await Warehouse3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Warehouse4 = await Warehouses.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Warehouse4?.setCompany) {
    await Warehouse4.setCompany(relatedCompany4);
  }
}

async function associatePayrollWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payroll0 = await Payrolls.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Payroll0?.setCompany) {
    await Payroll0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payroll1 = await Payrolls.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Payroll1?.setCompany) {
    await Payroll1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payroll2 = await Payrolls.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Payroll2?.setCompany) {
    await Payroll2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payroll3 = await Payrolls.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Payroll3?.setCompany) {
    await Payroll3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Payroll4 = await Payrolls.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Payroll4?.setCompany) {
    await Payroll4.setCompany(relatedCompany4);
  }
}

async function associateAttendanceWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Attendance0 = await Attendance.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Attendance0?.setCompany) {
    await Attendance0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Attendance1 = await Attendance.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Attendance1?.setCompany) {
    await Attendance1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Attendance2 = await Attendance.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Attendance2?.setCompany) {
    await Attendance2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Attendance3 = await Attendance.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Attendance3?.setCompany) {
    await Attendance3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Attendance4 = await Attendance.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Attendance4?.setCompany) {
    await Attendance4.setCompany(relatedCompany4);
  }
}

async function associateLeaveRequestWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const LeaveRequest0 = await LeaveRequests.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (LeaveRequest0?.setCompany) {
    await LeaveRequest0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const LeaveRequest1 = await LeaveRequests.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (LeaveRequest1?.setCompany) {
    await LeaveRequest1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const LeaveRequest2 = await LeaveRequests.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (LeaveRequest2?.setCompany) {
    await LeaveRequest2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const LeaveRequest3 = await LeaveRequests.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (LeaveRequest3?.setCompany) {
    await LeaveRequest3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const LeaveRequest4 = await LeaveRequests.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (LeaveRequest4?.setCompany) {
    await LeaveRequest4.setCompany(relatedCompany4);
  }
}

async function associateRecruitmentWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Recruitment0 = await Recruitment.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Recruitment0?.setCompany) {
    await Recruitment0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Recruitment1 = await Recruitment.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Recruitment1?.setCompany) {
    await Recruitment1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Recruitment2 = await Recruitment.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Recruitment2?.setCompany) {
    await Recruitment2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Recruitment3 = await Recruitment.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Recruitment3?.setCompany) {
    await Recruitment3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Recruitment4 = await Recruitment.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Recruitment4?.setCompany) {
    await Recruitment4.setCompany(relatedCompany4);
  }
}

async function associateBudgetWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Budget0 = await Budgets.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Budget0?.setCompany) {
    await Budget0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Budget1 = await Budgets.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Budget1?.setCompany) {
    await Budget1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Budget2 = await Budgets.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Budget2?.setCompany) {
    await Budget2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Budget3 = await Budgets.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Budget3?.setCompany) {
    await Budget3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Budget4 = await Budgets.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Budget4?.setCompany) {
    await Budget4.setCompany(relatedCompany4);
  }
}

async function associateTaxWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Tax0 = await Taxes.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Tax0?.setCompany) {
    await Tax0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Tax1 = await Taxes.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Tax1?.setCompany) {
    await Tax1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Tax2 = await Taxes.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Tax2?.setCompany) {
    await Tax2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Tax3 = await Taxes.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Tax3?.setCompany) {
    await Tax3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Tax4 = await Taxes.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Tax4?.setCompany) {
    await Tax4.setCompany(relatedCompany4);
  }
}

async function associateExpenseWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Expense0 = await Expenses.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Expense0?.setCompany) {
    await Expense0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Expense1 = await Expenses.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Expense1?.setCompany) {
    await Expense1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Expense2 = await Expenses.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Expense2?.setCompany) {
    await Expense2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Expense3 = await Expenses.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Expense3?.setCompany) {
    await Expense3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Expense4 = await Expenses.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Expense4?.setCompany) {
    await Expense4.setCompany(relatedCompany4);
  }
}

async function associateRevenueWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Revenue0 = await Revenues.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Revenue0?.setCompany) {
    await Revenue0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Revenue1 = await Revenues.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Revenue1?.setCompany) {
    await Revenue1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Revenue2 = await Revenues.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Revenue2?.setCompany) {
    await Revenue2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Revenue3 = await Revenues.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Revenue3?.setCompany) {
    await Revenue3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Revenue4 = await Revenues.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Revenue4?.setCompany) {
    await Revenue4.setCompany(relatedCompany4);
  }
}

async function associateLeadWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Lead0 = await Leads.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Lead0?.setCompany) {
    await Lead0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Lead1 = await Leads.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Lead1?.setCompany) {
    await Lead1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Lead2 = await Leads.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Lead2?.setCompany) {
    await Lead2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Lead3 = await Leads.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Lead3?.setCompany) {
    await Lead3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Lead4 = await Leads.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Lead4?.setCompany) {
    await Lead4.setCompany(relatedCompany4);
  }
}

async function associateTicketWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Ticket0 = await Tickets.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Ticket0?.setCompany) {
    await Ticket0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Ticket1 = await Tickets.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Ticket1?.setCompany) {
    await Ticket1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Ticket2 = await Tickets.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Ticket2?.setCompany) {
    await Ticket2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Ticket3 = await Tickets.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Ticket3?.setCompany) {
    await Ticket3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Ticket4 = await Tickets.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Ticket4?.setCompany) {
    await Ticket4.setCompany(relatedCompany4);
  }
}

async function associateMarketingCampaignWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const MarketingCampaign0 = await MarketingCampaigns.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (MarketingCampaign0?.setCompany) {
    await MarketingCampaign0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const MarketingCampaign1 = await MarketingCampaigns.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (MarketingCampaign1?.setCompany) {
    await MarketingCampaign1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const MarketingCampaign2 = await MarketingCampaigns.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (MarketingCampaign2?.setCompany) {
    await MarketingCampaign2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const MarketingCampaign3 = await MarketingCampaigns.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (MarketingCampaign3?.setCompany) {
    await MarketingCampaign3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const MarketingCampaign4 = await MarketingCampaigns.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (MarketingCampaign4?.setCompany) {
    await MarketingCampaign4.setCompany(relatedCompany4);
  }
}

async function associateAuditLogWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const AuditLog0 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (AuditLog0?.setCompany) {
    await AuditLog0.setCompany(relatedCompany0);
  }

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

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

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

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const AuditLog4 = await AuditLogs.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (AuditLog4?.setCompany) {
    await AuditLog4.setCompany(relatedCompany4);
  }
}

async function associateNotificationWithCompany() {
  const relatedCompany0 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Notification0 = await Notifications.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Notification0?.setCompany) {
    await Notification0.setCompany(relatedCompany0);
  }

  const relatedCompany1 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Notification1 = await Notifications.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Notification1?.setCompany) {
    await Notification1.setCompany(relatedCompany1);
  }

  const relatedCompany2 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Notification2 = await Notifications.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Notification2?.setCompany) {
    await Notification2.setCompany(relatedCompany2);
  }

  const relatedCompany3 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Notification3 = await Notifications.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Notification3?.setCompany) {
    await Notification3.setCompany(relatedCompany3);
  }

  const relatedCompany4 = await Companies.findOne({
    offset: Math.floor(Math.random() * (await Companies.count())),
  });
  const Notification4 = await Notifications.findOne({
    order: [['id', 'ASC']],
    offset: 4,
  });
  if (Notification4?.setCompany) {
    await Notification4.setCompany(relatedCompany4);
  }
}

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

    await Employees.bulkCreate(EmployeesData);

    await FinancialRecords.bulkCreate(FinancialRecordsData);

    await Inventories.bulkCreate(InventoriesData);

    await ManufacturingOrders.bulkCreate(ManufacturingOrdersData);

    await Procurements.bulkCreate(ProcurementsData);

    await Projects.bulkCreate(ProjectsData);

    await Sales.bulkCreate(SalesData);

    await Subscriptions.bulkCreate(SubscriptionsData);

    await Invoices.bulkCreate(InvoicesData);

    await Payments.bulkCreate(PaymentsData);

    await Contracts.bulkCreate(ContractsData);

    await Shipments.bulkCreate(ShipmentsData);

    await Warehouses.bulkCreate(WarehousesData);

    await Payrolls.bulkCreate(PayrollsData);

    await Attendance.bulkCreate(AttendanceData);

    await LeaveRequests.bulkCreate(LeaveRequestsData);

    await Recruitment.bulkCreate(RecruitmentData);

    await Budgets.bulkCreate(BudgetsData);

    await Taxes.bulkCreate(TaxesData);

    await Expenses.bulkCreate(ExpensesData);

    await Revenues.bulkCreate(RevenuesData);

    await Leads.bulkCreate(LeadsData);

    await Tickets.bulkCreate(TicketsData);

    await MarketingCampaigns.bulkCreate(MarketingCampaignsData);

    await AuditLogs.bulkCreate(AuditLogsData);

    await Notifications.bulkCreate(NotificationsData);

    await Companies.bulkCreate(CompaniesData);

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

      await associateUserWithCompany(),

      await associateAssetWithCompany(),

      await associateAssetWithCompany(),

      await associateEmployeeWithCompany(),

      await associateEmployeeWithCompany(),

      await associateFinancialRecordWithCompany(),

      await associateFinancialRecordWithCompany(),

      await associateInventoryWithCompany(),

      await associateInventoryWithCompany(),

      await associateManufacturingOrderWithCompany(),

      await associateManufacturingOrderWithCompany(),

      await associateProcurementWithCompany(),

      await associateProcurementWithCompany(),

      await associateProjectWithCompany(),

      await associateProjectWithCompany(),

      await associateSaleWithCompany(),

      await associateSaleWithCompany(),

      await associateSubscriptionWithCompany(),

      await associateSubscriptionWithCompany(),

      await associateInvoiceWithCompany(),

      await associatePaymentWithCompany(),

      await associateContractWithCompany(),

      await associateShipmentWithCompany(),

      await associateWarehouseWithCompany(),

      await associatePayrollWithCompany(),

      await associateAttendanceWithCompany(),

      await associateLeaveRequestWithCompany(),

      await associateRecruitmentWithCompany(),

      await associateBudgetWithCompany(),

      await associateTaxWithCompany(),

      await associateExpenseWithCompany(),

      await associateRevenueWithCompany(),

      await associateLeadWithCompany(),

      await associateTicketWithCompany(),

      await associateMarketingCampaignWithCompany(),

      await associateAuditLogWithCompany(),

      await associateNotificationWithCompany(),
    ]);
  },

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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