<?php

declare(strict_types=1);

namespace SecurWP\Modules\Scanner\Service;

if ( ! defined( 'ABSPATH' ) ) { exit; }

/**
 * Issue type constants and helpers.
 *
 * Replaces the PHP 8.1 enum so the plugin runs on PHP 7.4+.
 */
class IssueType {

    public const MALWARE        = 'malware';
    public const USER           = 'user';
    public const VULNERABILITY  = 'vulnerability';
    public const INTEGRITY      = 'integrity';
    public const FAKE_IMAGE     = 'fake_image';
    public const CONTENT        = 'content';
    public const BLOCKLIST      = 'blocklist';
    public const SKIPPED        = 'skipped';
    public const SENSITIVE_DATA = 'sensitive_data';
    public const UNKNOWN        = 'unknown';

    /** @var string */
    public $value;

    /** @var string[] All known type strings. */
    private static $all = [
        self::MALWARE,
        self::USER,
        self::VULNERABILITY,
        self::INTEGRITY,
        self::FAKE_IMAGE,
        self::CONTENT,
        self::BLOCKLIST,
        self::SKIPPED,
        self::SENSITIVE_DATA,
        self::UNKNOWN,
    ];

    private function __construct( string $value ) {
        $this->value = $value;
    }

    /**
     * Build an instance from a string value, or null if unrecognised.
     *
     * @param string $value
     * @return self|null
     */
    public static function tryFrom( string $value ) {
        if ( in_array( $value, self::$all, true ) ) {
            return new self( $value );
        }
        return null;
    }

    /**
     * Get the recommended UI layout for this type.
     *
     * @return string
     */
    public function getLayout(): string {
        switch ( $this->value ) {
            case self::MALWARE:
                return 'malware_card';
            case self::USER:
                return 'user_card';
            case self::VULNERABILITY:
                return 'vulnerability_card';
            case self::INTEGRITY:
                return 'integrity_card';
            case self::FAKE_IMAGE:
                return 'integrity_card';
            case self::CONTENT:
                return 'content_card';
            case self::BLOCKLIST:
                return 'blocklist_card';
            default:
                return 'generic_card';
        }
    }

    /**
     * Get the human-readable label.
     *
     * @return string
     */
	    public function label(): string {
	        switch ( $this->value ) {
            case self::MALWARE:
                return 'Malware';
            case self::USER:
                return 'User Identity';
            case self::VULNERABILITY:
                return 'Vulnerability';
	            case self::INTEGRITY:
	                return 'File Integrity';
	            case self::FAKE_IMAGE:
	                return 'Suspicious Image';
	            case self::CONTENT:
	                return 'Content Safety';
            case self::BLOCKLIST:
                return 'Reputation & Blocklist';
            case self::SKIPPED:
                return 'Skipped Item';
            case self::SENSITIVE_DATA:
                return 'Sensitive Data Exposure';
            default:
                return 'Other Issue';
        }
    }
}
