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

const Customers = db.customers;

const Employees = db.employees;

const FinancialAccounts = db.financial_accounts;

const Orders = db.orders;

const Products = db.products;

const Projects = db.projects;

const PurchaseOrders = db.purchase_orders;

const Tasks = db.tasks;

const Transactions = db.transactions;

const Vendors = db.vendors;

const Invoices = db.invoices;

const Payments = db.payments;

const Subscriptions = db.subscriptions;

const Contracts = db.contracts;

const Shipments = db.shipments;

const Warehouses = db.warehouses;

const Assets = db.assets;

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 Companies = db.companies;

const CustomersData = [
  {
    name: 'John Doe',

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

    // type code here for "relation_many" field

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

  {
    name: 'Jane Smith',

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

    // type code here for "relation_many" field

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

  {
    name: 'Michael Brown',

    email: 'michael.brown@example.com',

    // type code here for "relation_many" field

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

  {
    name: 'Lisa Jones',

    email: 'lisa.jones@example.com',

    // type code here for "relation_many" field

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

const EmployeesData = [
  {
    first_name: 'John',

    last_name: 'Doe',

    // type code here for "relation_one" field

    role: 'DepartmentHead',

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

  {
    first_name: 'Jane',

    last_name: 'Smith',

    // type code here for "relation_one" field

    role: 'Employee',

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

  {
    first_name: 'Michael',

    last_name: 'Brown',

    // type code here for "relation_one" field

    role: 'DepartmentHead',

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

  {
    first_name: 'Lisa',

    last_name: 'Jones',

    // type code here for "relation_one" field

    role: 'ITManager',

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

const FinancialAccountsData = [
  {
    account_name: 'Cash',

    account_type: 'Equity',

    balance: 10000,

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

  {
    account_name: 'Accounts Receivable',

    account_type: 'Expense',

    balance: 5000,

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

  {
    account_name: 'Accounts Payable',

    account_type: 'Expense',

    balance: 3000,

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

  {
    account_name: 'Revenue',

    account_type: 'Equity',

    balance: 15000,

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

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

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

    total_amount: 250,

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

  {
    // type code here for "relation_one" field

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

    total_amount: 300,

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

  {
    // type code here for "relation_one" field

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

    total_amount: 150,

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

  {
    // type code here for "relation_one" field

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

    total_amount: 400,

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

const ProductsData = [
  {
    product_name: 'ERP Software',

    price: 5000,

    // type code here for "relation_many" field

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

  {
    product_name: 'CRM Solution',

    price: 3000,

    // type code here for "relation_many" field

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

  {
    product_name: 'HR Management Tool',

    price: 2000,

    // type code here for "relation_many" field

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

  {
    product_name: 'Inventory System',

    price: 1500,

    // type code here for "relation_many" field

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

const ProjectsData = [
  {
    project_name: 'ERP Implementation',

    start_date: new Date('2023-09-01T09:00:00Z'),

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

    // type code here for "relation_many" field

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

  {
    project_name: 'Website Redesign',

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

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

    // type code here for "relation_many" field

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

  {
    project_name: 'Mobile App Development',

    start_date: new Date('2023-08-01T09:00:00Z'),

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

    // type code here for "relation_many" field

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

  {
    project_name: 'Marketing Campaign',

    start_date: new Date('2023-07-01T09:00:00Z'),

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

    // type code here for "relation_many" field

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

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

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

    total_cost: 1000,

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

  {
    // type code here for "relation_one" field

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

    total_cost: 1500,

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

  {
    // type code here for "relation_one" field

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

    total_cost: 2000,

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

  {
    // type code here for "relation_one" field

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

    total_cost: 2500,

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

const TasksData = [
  {
    task_name: 'Design Database Schema',

    // type code here for "relation_one" field

    status: 'Done',

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

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

  {
    task_name: 'Develop API Endpoints',

    // type code here for "relation_one" field

    status: 'InProgress',

    due_date: new Date('2023-10-15T17:00:00Z'),

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

  {
    task_name: 'Create User Interface',

    // type code here for "relation_one" field

    status: 'InProgress',

    due_date: new Date('2023-10-20T17:00:00Z'),

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

  {
    task_name: 'Test Application',

    // type code here for "relation_one" field

    status: 'ToDo',

    due_date: new Date('2023-10-25T17:00:00Z'),

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

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

    // type code here for "relation_one" field

    amount: 200,

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

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

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    amount: 150,

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

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

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    amount: 300,

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

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

  {
    // type code here for "relation_one" field

    // type code here for "relation_one" field

    amount: 400,

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

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

const VendorsData = [
  {
    vendor_name: 'Tech Supplies Co.',

    contact_email: 'contact@techsupplies.com',

    // type code here for "relation_many" field

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

  {
    vendor_name: 'Office Essentials Ltd.',

    contact_email: 'info@officeessentials.com',

    // type code here for "relation_many" field

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

  {
    vendor_name: 'Green Energy Partners',

    contact_email: 'sales@greenenergy.com',

    // type code here for "relation_many" field

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

  {
    vendor_name: 'IT Solutions Inc.',

    contact_email: 'support@itsolutions.com',

    // type code here for "relation_many" 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
  },
];

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
  },
];

const SubscriptionsData = [
  {
    // 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
  },
];

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
  },
];

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
  },
];

const AssetsData = [
  {
    // 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
  },
];

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
  },
];

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
  },
];

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
  },
];

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
  },
];

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
  },
];

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
  },
];

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
  },
];

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

  {
    name: 'Green Earth Solutions',
  },

  {
    name: 'HealthFirst Corp.',
  },

  {
    name: 'EduSmart Learning',
  },
];

// 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);
  }
}

// Similar logic for "relation_many"

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

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

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

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

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);
  }
}

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);
  }
}

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

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

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

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

async function associateOrderWithCustomer() {
  const relatedCustomer0 = await Customers.findOne({
    offset: Math.floor(Math.random() * (await Customers.count())),
  });
  const Order0 = await Orders.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Order0?.setCustomer) {
    await Order0.setCustomer(relatedCustomer0);
  }

  const relatedCustomer1 = await Customers.findOne({
    offset: Math.floor(Math.random() * (await Customers.count())),
  });
  const Order1 = await Orders.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Order1?.setCustomer) {
    await Order1.setCustomer(relatedCustomer1);
  }

  const relatedCustomer2 = await Customers.findOne({
    offset: Math.floor(Math.random() * (await Customers.count())),
  });
  const Order2 = await Orders.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Order2?.setCustomer) {
    await Order2.setCustomer(relatedCustomer2);
  }

  const relatedCustomer3 = await Customers.findOne({
    offset: Math.floor(Math.random() * (await Customers.count())),
  });
  const Order3 = await Orders.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Order3?.setCustomer) {
    await Order3.setCustomer(relatedCustomer3);
  }
}

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

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

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

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

// Similar logic for "relation_many"

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

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

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

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

// Similar logic for "relation_many"

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);
  }
}

async function associatePurchaseOrderWithVendor() {
  const relatedVendor0 = await Vendors.findOne({
    offset: Math.floor(Math.random() * (await Vendors.count())),
  });
  const PurchaseOrder0 = await PurchaseOrders.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (PurchaseOrder0?.setVendor) {
    await PurchaseOrder0.setVendor(relatedVendor0);
  }

  const relatedVendor1 = await Vendors.findOne({
    offset: Math.floor(Math.random() * (await Vendors.count())),
  });
  const PurchaseOrder1 = await PurchaseOrders.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (PurchaseOrder1?.setVendor) {
    await PurchaseOrder1.setVendor(relatedVendor1);
  }

  const relatedVendor2 = await Vendors.findOne({
    offset: Math.floor(Math.random() * (await Vendors.count())),
  });
  const PurchaseOrder2 = await PurchaseOrders.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (PurchaseOrder2?.setVendor) {
    await PurchaseOrder2.setVendor(relatedVendor2);
  }

  const relatedVendor3 = await Vendors.findOne({
    offset: Math.floor(Math.random() * (await Vendors.count())),
  });
  const PurchaseOrder3 = await PurchaseOrders.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (PurchaseOrder3?.setVendor) {
    await PurchaseOrder3.setVendor(relatedVendor3);
  }
}

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

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

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

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

async function associateTaskWithProject() {
  const relatedProject0 = await Projects.findOne({
    offset: Math.floor(Math.random() * (await Projects.count())),
  });
  const Task0 = await Tasks.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Task0?.setProject) {
    await Task0.setProject(relatedProject0);
  }

  const relatedProject1 = await Projects.findOne({
    offset: Math.floor(Math.random() * (await Projects.count())),
  });
  const Task1 = await Tasks.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Task1?.setProject) {
    await Task1.setProject(relatedProject1);
  }

  const relatedProject2 = await Projects.findOne({
    offset: Math.floor(Math.random() * (await Projects.count())),
  });
  const Task2 = await Tasks.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Task2?.setProject) {
    await Task2.setProject(relatedProject2);
  }

  const relatedProject3 = await Projects.findOne({
    offset: Math.floor(Math.random() * (await Projects.count())),
  });
  const Task3 = await Tasks.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Task3?.setProject) {
    await Task3.setProject(relatedProject3);
  }
}

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

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

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

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

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

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

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

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

async function associateTransactionWithAccount() {
  const relatedAccount0 = await FinancialAccounts.findOne({
    offset: Math.floor(Math.random() * (await FinancialAccounts.count())),
  });
  const Transaction0 = await Transactions.findOne({
    order: [['id', 'ASC']],
    offset: 0,
  });
  if (Transaction0?.setAccount) {
    await Transaction0.setAccount(relatedAccount0);
  }

  const relatedAccount1 = await FinancialAccounts.findOne({
    offset: Math.floor(Math.random() * (await FinancialAccounts.count())),
  });
  const Transaction1 = await Transactions.findOne({
    order: [['id', 'ASC']],
    offset: 1,
  });
  if (Transaction1?.setAccount) {
    await Transaction1.setAccount(relatedAccount1);
  }

  const relatedAccount2 = await FinancialAccounts.findOne({
    offset: Math.floor(Math.random() * (await FinancialAccounts.count())),
  });
  const Transaction2 = await Transactions.findOne({
    order: [['id', 'ASC']],
    offset: 2,
  });
  if (Transaction2?.setAccount) {
    await Transaction2.setAccount(relatedAccount2);
  }

  const relatedAccount3 = await FinancialAccounts.findOne({
    offset: Math.floor(Math.random() * (await FinancialAccounts.count())),
  });
  const Transaction3 = await Transactions.findOne({
    order: [['id', 'ASC']],
    offset: 3,
  });
  if (Transaction3?.setAccount) {
    await Transaction3.setAccount(relatedAccount3);
  }
}

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

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

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

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

// Similar logic for "relation_many"

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

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

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

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

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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);
  }
}

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

    await Employees.bulkCreate(EmployeesData);

    await FinancialAccounts.bulkCreate(FinancialAccountsData);

    await Orders.bulkCreate(OrdersData);

    await Products.bulkCreate(ProductsData);

    await Projects.bulkCreate(ProjectsData);

    await PurchaseOrders.bulkCreate(PurchaseOrdersData);

    await Tasks.bulkCreate(TasksData);

    await Transactions.bulkCreate(TransactionsData);

    await Vendors.bulkCreate(VendorsData);

    await Invoices.bulkCreate(InvoicesData);

    await Payments.bulkCreate(PaymentsData);

    await Subscriptions.bulkCreate(SubscriptionsData);

    await Contracts.bulkCreate(ContractsData);

    await Shipments.bulkCreate(ShipmentsData);

    await Warehouses.bulkCreate(WarehousesData);

    await Assets.bulkCreate(AssetsData);

    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 Companies.bulkCreate(CompaniesData);

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

      await associateUserWithCompany(),

      // Similar logic for "relation_many"

      await associateCustomerWithCompany(),

      await associateEmployeeWithCompany(),

      await associateEmployeeWithCompany(),

      await associateFinancialAccountWithCompany(),

      await associateOrderWithCustomer(),

      await associateOrderWithCompany(),

      // Similar logic for "relation_many"

      await associateProductWithCompany(),

      // Similar logic for "relation_many"

      await associateProjectWithCompany(),

      await associatePurchaseOrderWithVendor(),

      await associatePurchaseOrderWithCompany(),

      await associateTaskWithProject(),

      await associateTaskWithCompany(),

      await associateTransactionWithCompany(),

      await associateTransactionWithAccount(),

      await associateTransactionWithCompany(),

      // Similar logic for "relation_many"

      await associateVendorWithCompany(),

      await associateInvoiceWithCompany(),

      await associatePaymentWithCompany(),

      await associateSubscriptionWithCompany(),

      await associateContractWithCompany(),

      await associateShipmentWithCompany(),

      await associateWarehouseWithCompany(),

      await associateAssetWithCompany(),

      await associatePayrollWithCompany(),

      await associateAttendanceWithCompany(),

      await associateLeaveRequestWithCompany(),

      await associateRecruitmentWithCompany(),

      await associateBudgetWithCompany(),

      await associateTaxWithCompany(),

      await associateExpenseWithCompany(),

      await associateRevenueWithCompany(),
    ]);
  },

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    await queryInterface.bulkDelete('assets', 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('companies', null, {});
  },
};
