<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class FreshOrderSeed extends Command
{
    protected $signature = 'seed:fresh-orders';
    protected $description = 'Fresh seed orders and order items';

    public function handle()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
        DB::table('order_histories')->truncate();
        DB::table('order_delivery_dates')->truncate();
        DB::table('order_addresses')->truncate();
        DB::table('order_taxes')->truncate();
        DB::table('order_items')->truncate();
        DB::table('transactions')->truncate();
        DB::table('order_item_categories')->truncate();
        DB::table('orders')->truncate();
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');

        $this->call('db:seed', ['--class' => 'OrderTableSeeder']);
        $this->call('db:seed', ['--class' => 'OrderItemCategoryTableSeeder']);
        $this->call('db:seed', ['--class' => 'TransactionTableSeeder']);
        $this->call('db:seed', ['--class' => 'OrderItemTableSeeder']);
        $this->call('db:seed', ['--class' => 'OrderTaxTableSeeder']);
        $this->call('db:seed', ['--class' => 'OrderAddressTableSeeder']);
        $this->call('db:seed', ['--class' => 'OrderDeliveryDateSeeder']);
        $this->call('db:seed', ['--class' => 'OrderHistoryTableSeeder']);

        $this->info('Fresh order and order items seeded!');
    }
}