<?php

namespace Tests\Unit\Services;

use App\Services\ReferenceGeneratorService;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class ReferenceGeneratorServiceTest extends TestCase
{
    public function test_candidat_reference_format(): void
    {
        DB::shouldReceive('table')
            ->with('candidats')
            ->andReturnSelf();
        DB::shouldReceive('whereYear')
            ->with('created_at', date('Y'))
            ->andReturnSelf();
        DB::shouldReceive('count')
            ->andReturn(0);

        $service = new ReferenceGeneratorService();
        $reference = $service->candidat();

        $this->assertMatchesRegularExpression('/^CND-\d{4}-\d{4}$/', $reference);
    }

    public function test_besoin_reference_format(): void
    {
        DB::shouldReceive('table')
            ->with('besoins')
            ->andReturnSelf();
        DB::shouldReceive('whereYear')
            ->with('created_at', date('Y'))
            ->andReturnSelf();
        DB::shouldReceive('count')
            ->andReturn(0);

        $service = new ReferenceGeneratorService();
        $reference = $service->besoin();

        $this->assertMatchesRegularExpression('/^BSN-\d{4}-\d{4}$/', $reference);
    }

    public function test_mission_reference_format(): void
    {
        DB::shouldReceive('table')
            ->with('missions')
            ->andReturnSelf();
        DB::shouldReceive('whereYear')
            ->with('created_at', date('Y'))
            ->andReturnSelf();
        DB::shouldReceive('count')
            ->andReturn(0);

        $service = new ReferenceGeneratorService();
        $reference = $service->mission();

        $this->assertMatchesRegularExpression('/^MSN-\d{4}-\d{4}$/', $reference);
    }

    public function test_paiement_reference_format(): void
    {
        DB::shouldReceive('table')
            ->with('paiements')
            ->andReturnSelf();
        DB::shouldReceive('whereYear')
            ->with('created_at', date('Y'))
            ->andReturnSelf();
        DB::shouldReceive('count')
            ->andReturn(0);

        $service = new ReferenceGeneratorService();
        $reference = $service->paiement();

        $this->assertMatchesRegularExpression('/^PAY-\d{4}-\d{4}$/', $reference);
    }
}
