<?php

namespace UltraguardPro\modules\woo_security\db;

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

use UltraguardPro\db\BaseTable;

class SkimmerScanResultsTable extends BaseTable {

    protected $table_name  = 'ultraguard_skimmer_scan_results';
    protected $cache_group = 'ultraguard_skimmer_scan_results';

    public function get_defaults(): array {
        return [
            'id'             => 0,
            'file_path'      => '',
            'finding_type'   => '',
            'severity'       => 'medium',
            'details'        => '',
            'first_detected' => '',
            'created_at'     => '',
            'updated_at'     => '',
        ];
    }

    protected function validate_data( $data ) {
        return $this->validate_required( (array) $data, [ 'file_path', 'finding_type', 'severity' ] ) ? $data : false;
    }

    protected function sanitize_data( $data ): array {
        $out = [];
        foreach ( (array) $data as $key => $value ) {
            $out[ $key ] = is_string( $value ) ? sanitize_text_field( $value ) : $value;
        }
        return $out;
    }

    public function get_recent( int $limit = 50, string $date_field = 'created_at', array $conditions = [], bool $use_cache = true ): array {
        return (array) $this->get_by( $conditions, max( 1, min( 200, $limit ) ), $date_field, 'DESC', 0, $use_cache );
    }
}
