<?php

declare(strict_types=1);

use App\Models\Coupon;

it('validates a valid coupon', function (): void {
    $coupon = Coupon::factory()->create([
        'max_uses' => 100,
        'times_used' => 50,
        'expires_at' => now()->addMonth(),
    ]);

    expect($coupon->isValid())->toBeTrue();
});

it('rejects an expired coupon', function (): void {
    $coupon = Coupon::factory()->create([
        'expires_at' => now()->subDay(),
    ]);

    expect($coupon->isValid())->toBeFalse();
});

it('rejects a maxed out coupon', function (): void {
    $coupon = Coupon::factory()->create([
        'max_uses' => 5,
        'times_used' => 5,
    ]);

    expect($coupon->isValid())->toBeFalse();
});

it('accepts a coupon with no usage limit', function (): void {
    $coupon = Coupon::factory()->create([
        'max_uses' => null,
        'times_used' => 999,
        'expires_at' => now()->addMonth(),
    ]);

    expect($coupon->isValid())->toBeTrue();
});

it('accepts a coupon with no expiry', function (): void {
    $coupon = Coupon::factory()->create([
        'max_uses' => 100,
        'times_used' => 0,
        'expires_at' => null,
    ]);

    expect($coupon->isValid())->toBeTrue();
});
