<?php

namespace Tests\Unit\Framework;

use Openguru\OpenCartFramework\Http\JsonResponse;
use PHPUnit\Framework\TestCase;

class JsonResponseTest extends TestCase
{
    public function testConstructorSetsDataAndCode(): void
    {
        $data = ['key' => 'value'];
        $code = 201;
        $response = new JsonResponse($data, $code);

        $this->assertEquals($data, $response->getData());
        $this->assertEquals($code, $response->getCode());
    }

    public function testDefaultCodeIs200(): void
    {
        $data = ['key' => 'value'];
        $response = new JsonResponse($data);

        $this->assertEquals(JsonResponse::HTTP_OK, $response->getCode());
    }

    public function testGetDataReturnsCorrectData(): void
    {
        $data = ['message' => 'success', 'items' => [1, 2, 3]];
        $response = new JsonResponse($data);

        $this->assertEquals($data, $response->getData());
    }

    public function testGetCodeReturnsCorrectCode(): void
    {
        $response = new JsonResponse([], 404);

        $this->assertEquals(404, $response->getCode());
    }

    public function testResponseInheritsFromResponse(): void
    {
        $response = new JsonResponse([]);

        $this->assertInstanceOf(\Openguru\OpenCartFramework\Http\Response::class, $response);
    }

    public function testCanUseHttpConstants(): void
    {
        $response = new JsonResponse([], JsonResponse::HTTP_CREATED);

        $this->assertEquals(201, $response->getCode());
    }
}

