<?php

namespace App\Services;

use Illuminate\Support\Fluent;
use function config;
use function fluent;

class Command extends \LaravelZero\Framework\Commands\Command
{

    protected Fluent $env;

    public function __construct()
    {
        parent::__construct();

        $this->loadProjectEnv();
    }


    public function loadProjectEnv(): void
    {

        $file = getcwd() . '/.env';

        if (!file_exists($file)) {
//            $this->error('No .env file found');
            return;
        }

        $parsed = parse_ini_file($file, false, INI_SCANNER_RAW);

        $this->env = fluent(is_array($parsed) ? $parsed : []);

        config()->set('project.env', $this->env);

        $composeFiles = $this->env->get('CLI_COMPOSE_FILES');

        if ($composeFiles) {
            config()->set(
                'project.compose_files',
                array_map('trim', explode(',', $composeFiles)),
            );
        }
    }

}
