<?php

declare(strict_types=1);

namespace SecurWP\Modules\Scanner;

use SecurWP\Includes\Interfaces\Module;
use SecurWP\Modules\Scanner\Repository\IssueRepository;

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


/**
 * Synchronous scanner for basic site health and configuration checks.
 */
class SiteHealth  {

    public function get_title() {
        return 'Site Health';
    }

    public function run() {
        $issues = [];

        $disk_free = @disk_free_space( ABSPATH );
        if ( $disk_free !== false ) {
            if ( $disk_free < 100 * 1024 * 1024 ) {
                $key = 'site_health_disk_space_low';
                $issues[] = [
                    'id'       => 'disk_space_low',
                    'hash'     => IssueRepository::generateHash( 'site_health', $key ),
                    'type'     => 'site_health',
                    'severity' => 'medium',
                    'status'   => 'warning',
                    'message'  => 'Low disk space detected: ' . size_format( $disk_free ),
                    'file'     => 'Disk Space',
                ];
            }
        }

        return [
            'issues' => $issues,
            'count'  => count( $issues )
        ];
    }
}
