<?php

namespace App\Tests\Shared;

use App\Shared\Constant\ErrorCodes;
use PHPUnit\Framework\TestCase;

/**
 * The legacy domain string codes are now centralised in ErrorCodes. Their wire
 * values must stay identical (clients may read them) and message() must resolve
 * them rather than returning the "unknown" fallback.
 */
class ErrorCodesTest extends TestCase
{
    public function testWireValuesArePreserved(): void
    {
        $this->assertSame('SLOT_TAKEN', ErrorCodes::SLOT_TAKEN);
        $this->assertSame('VALIDATION', ErrorCodes::VALIDATION);
        $this->assertSame('USER_NOT_FOUND', ErrorCodes::USER_NOT_FOUND);
        $this->assertSame('DOCTOR_NOT_FOUND', ErrorCodes::DOCTOR_NOT_FOUND);
        $this->assertSame('FORBIDDEN', ErrorCodes::FORBIDDEN);
        $this->assertSame('ERR_ACCESS_DENIED', ErrorCodes::ERR_ACCESS_DENIED);
    }

    public function testMessagesResolve(): void
    {
        $codes = [
            ErrorCodes::VALIDATION, ErrorCodes::FORBIDDEN, ErrorCodes::NOT_FOUND,
            ErrorCodes::USER_NOT_FOUND, ErrorCodes::DOCTOR_NOT_FOUND, ErrorCodes::DOCTOR_EXISTS,
            ErrorCodes::CLINIC_NOT_FOUND, ErrorCodes::SLOT_TAKEN, ErrorCodes::SLOT_PAST,
            ErrorCodes::INVALID_ROLE, ErrorCodes::DUPLICATE_REQUEST, ErrorCodes::ERR_GONE,
            ErrorCodes::ERR_MOVED, ErrorCodes::ERR_ACCESS_DENIED,
        ];
        foreach ($codes as $code) {
            $this->assertNotSame('خطای ناشناخته', ErrorCodes::message($code), "message() did not resolve $code");
        }
    }
}
