<?php

namespace Lucent\Setup\Step;

use Lucent\Setup\Data\SetupStep;

class ComposerStep implements IStep
{

    public function __invoke(): SetupStep
    {

        $composerFile = json_decode(file_get_contents(base_path("composer.json")), true);

        $postAutoloadDumpList = data_get($composerFile, "scripts.post-autoload-dump", []);

        $name = "Composer File";

        $instructions = <<<EOD
# Append this line in post-autoload-dump in your composer.json.:

"@php artisan vendor:publish --tag=lucent --force"

example: 
{
  "scripts": {
    "post-autoload-dump": [
      "@php artisan vendor:publish --tag=lucent --force"
    ]
  }
}

EOD;


        return match (in_array("@php artisan vendor:publish --tag=lucent --force", $postAutoloadDumpList)) {
            true => SetupStep::makeSuccess($name, $instructions),
            false => SetupStep::makeFail($name, $instructions),
        };
    }
}