<?php

namespace App\Console\Commands\V2;


use App\Classes\Jobs\Commands\V2\OneTimeBatchProcessEInvoicesV2CommandJob;
use App\Classes\Jobs\Commands\V2\ProcessBookingForEInvoiceV2CommandJob;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\TransactionType;
use Illuminate\Console\Command;
use App\Models\Booking;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Log;

class RegenerateInvoiceEInvoiceV2Comman extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */

    protected $signature = 'regenerate-invoice-einvoice-command';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Regenerate Invoice E-Invoices';


    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $bookings = Booking::whereIn('invoice_status', [ApprovalStatus::APPROVED])->whereIn('status', [ApprovalStatus::APPROVED])->get();

        $count = 0;
        foreach ($bookings as $booking) {
            $count++;
            $start = Carbon::parse('2026-03-05 04:00:00');
            $end = Carbon::parse('2026-03-05 05:00:00');

            if ($booking->updated_at->between($start, $end)) {
                Log::info('Processed: ' . $count . ', Booking ID: ' . $booking->marking . ', Booking updated: ' . $booking->updated_at);
                $booking->status = 3;
                $booking->save();
            }
            Log::info('Processed: ' . $count . ', Booking ID: ' . $booking->marking . ', Booking ID: ' . $booking->marking);
        }
    }
}
