<?php

declare(strict_types=1);

namespace SiteFort\Modules\Scanner;

use SiteFort\Includes\Interfaces\Module;
use SiteFort\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 )
        ];
    }
}
