<?php

namespace Tests\Unit;

use PHPUnit\Framework\TestCase;
use App\Core\Validator;

class ValidatorTest extends TestCase
{
    public function testRequiredRule(): void
    {
        $validator = Validator::make(
            ['name' => ''],
            ['name' => 'required']
        );
        $this->assertTrue($validator->fails());
        $this->assertNotEmpty($validator->errors()['name']);
    }

    public function testEmailRule(): void
    {
        $validator = Validator::make(
            ['email' => 'invalid-email'],
            ['email' => 'email']
        );
        $this->assertTrue($validator->fails());
        
        $validator = Validator::make(
            ['email' => 'test@example.com'],
            ['email' => 'email']
        );
        $this->assertTrue($validator->passes());
    }

    public function testNumericRule(): void
    {
        $validator = Validator::make(
            ['age' => 'abc'],
            ['age' => 'numeric']
        );
        $this->assertTrue($validator->fails());
        
        $validator = Validator::make(
            ['age' => '25'],
            ['age' => 'numeric']
        );
        $this->assertTrue($validator->passes());
    }

    public function testMinRule(): void
    {
        $validator = Validator::make(
            ['password' => '123'],
            ['password' => 'min:8']
        );
        $this->assertTrue($validator->fails());
        
        $validator = Validator::make(
            ['password' => '12345678'],
            ['password' => 'min:8']
        );
        $this->assertTrue($validator->passes());
    }

    public function testMaxRule(): void
    {
        $validator = Validator::make(
            ['name' => str_repeat('a', 101)],
            ['name' => 'max:100']
        );
        $this->assertTrue($validator->fails());
        
        $validator = Validator::make(
            ['name' => 'John'],
            ['name' => 'max:100']
        );
        $this->assertTrue($validator->passes());
    }

    public function testInRule(): void
    {
        $validator = Validator::make(
            ['status' => 'invalid'],
            ['status' => 'in:active,inactive']
        );
        $this->assertTrue($validator->fails());
        
        $validator = Validator::make(
            ['status' => 'active'],
            ['status' => 'in:active,inactive']
        );
        $this->assertTrue($validator->passes());
    }
}
