<?php

require_once __DIR__ . '/response.php';

class Validator
{
    public static function required($data, $fields)
    {
        foreach ($fields as $field) {

            if (!isset($data[$field]) || trim($data[$field]) === '') {

                Response::error("Field required: " . $field);

            }
        }
    }

    public static function email($email)
    {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            Response::error("Invalid email format");
        }
    }

    public static function phone($phone)
    {
        if (!preg_match('/^[0-9]{10}$/', $phone)) {
            Response::error("Invalid phone number");
        }
    }
}