<?php

declare(strict_types=1);

namespace App\Framework\Config;

enum EnvironmentType: string
{
    case DEV = 'development';
    case STAGING = 'staging';
    case PROD = 'production';
    case TESTING = 'testing';

    public function isProduction(): bool
    {
        return $this === self::PROD;
    }

    public function isDevelopment(): bool
    {
        return $this === self::DEV;
    }

    public function isStaging(): bool
    {
        return $this === self::STAGING;
    }

    public function isTesting(): bool
    {
        return $this === self::TESTING;
    }

    public function isDebugEnabled(): bool
    {
        return $this === self::DEV;
    }

    public function isProductionLike(): bool
    {
        return $this === self::PROD || $this === self::STAGING;
    }

    public static function fromEnvironment(Environment $env): self
    {
        $envValue = $env->getString('APP_ENV', 'development');

        return match(strtolower($envValue)) {
            'production', 'prod' => self::PROD,
            'staging', 'stage' => self::STAGING,
            'testing', 'test' => self::TESTING,
            'development', 'dev', 'local' => self::DEV,
            default => self::DEV
        };
    }
}
