<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class ClearOrderDataSeeder extends Seeder
{
  public function run()
  {
    echo "Clearing order-related tables...\n";

    // Disable foreign key checks temporarily
    $this->db->query('SET FOREIGN_KEY_CHECKS = 0');

    // Clear tables in reverse dependency order
    $this->db->table('ordercom')->truncate();
    echo "  - ordercom truncated\n";

    $this->db->table('orderstatus')->truncate();
    echo "  - orderstatus truncated\n";

    $this->db->table('patres')->truncate();
    echo "  - patres truncated\n";

    $this->db->table('specimenstatus')->truncate();
    echo "  - specimenstatus truncated\n";

    $this->db->table('specimen')->truncate();
    echo "  - specimen truncated\n";

    $this->db->table('ordertest')->truncate();
    echo "  - ordertest truncated\n";

    // Re-enable foreign key checks
    $this->db->query('SET FOREIGN_KEY_CHECKS = 1');

    echo "\nAll order-related tables cleared successfully!\n";
  }
}
