<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class FoodicsAutomationCommand extends Command
{
    protected $signature = 'foodics:automation';
    protected $description = 'Run Foodics automation API every 5 minutes';

    public function handle()
    {
        $response = Http::withHeaders([
            'Accept' => 'application/json',
            'Content-Type' => 'application/json',
            'X-Custom-Header' => env('MIDDLEWARE_TOKEN'),
        ])->get(env('APP_URL') . '/api/foodics/automation');

        if ($response->successful()) {
            Log::channel('foodics')->info("Foodics Automation API call successful: " . $response->body());
        } else {
            Log::channel('foodics')->error("Foodics Automation API call failed: " . $response->body());
        }
    }
}
