<?php

declare(strict_types=1);

namespace App\Tests\Unit\Enum;

use App\Enum\DeviceModel;
use App\Enum\Orientation;
use PHPUnit\Framework\TestCase;

/**
 * width()/height() must follow orientation, but nativeWidth()/nativeHeight()
 * are the EPD's hardware scan dimensions and must NOT depend on orientation
 * (the renderer pre-rotates non-native images and streams raw bytes).
 *
 * V1 panel is wide-native (800×480 landscape); V2 is tall-native (1200×1600
 * portrait). nativeOrientation() decides whether rendering rotates.
 */
class DeviceModelTest extends TestCase
{
    public function test_v1_landscape_dimensions_are_800x480(): void
    {
        $this->assertSame(800, DeviceModel::V1->width(Orientation::Landscape));
        $this->assertSame(480, DeviceModel::V1->height(Orientation::Landscape));
    }

    public function test_v1_portrait_dimensions_are_swapped(): void
    {
        $this->assertSame(480, DeviceModel::V1->width(Orientation::Portrait));
        $this->assertSame(800, DeviceModel::V1->height(Orientation::Portrait));
    }

    public function test_v1_native_dimensions_ignore_orientation(): void
    {
        $this->assertSame(800, DeviceModel::V1->nativeWidth());
        $this->assertSame(480, DeviceModel::V1->nativeHeight());
    }

    public function test_v1_native_orientation_is_landscape(): void
    {
        $this->assertSame(Orientation::Landscape, DeviceModel::V1->nativeOrientation());
    }

    public function test_v2_portrait_dimensions_are_1200x1600(): void
    {
        $this->assertSame(1200, DeviceModel::V2->width(Orientation::Portrait));
        $this->assertSame(1600, DeviceModel::V2->height(Orientation::Portrait));
    }

    public function test_v2_landscape_dimensions_are_swapped(): void
    {
        $this->assertSame(1600, DeviceModel::V2->width(Orientation::Landscape));
        $this->assertSame(1200, DeviceModel::V2->height(Orientation::Landscape));
    }

    public function test_v2_native_dimensions_ignore_orientation(): void
    {
        $this->assertSame(1200, DeviceModel::V2->nativeWidth());
        $this->assertSame(1600, DeviceModel::V2->nativeHeight());
    }

    public function test_v2_native_orientation_is_portrait(): void
    {
        $this->assertSame(Orientation::Portrait, DeviceModel::V2->nativeOrientation());
    }

    public function test_panel_id_round_trips(): void
    {
        $this->assertSame(DeviceModel::V1, DeviceModel::fromPanelId(DeviceModel::V1->panelId()));
        $this->assertSame(DeviceModel::V2, DeviceModel::fromPanelId(DeviceModel::V2->panelId()));
    }

    public function test_panel_ids_are_distinct(): void
    {
        $this->assertNotSame(DeviceModel::V1->panelId(), DeviceModel::V2->panelId());
    }

    public function test_from_panel_id_returns_null_for_unknown(): void
    {
        $this->assertNull(DeviceModel::fromPanelId('not-a-real-panel'));
        $this->assertNull(DeviceModel::fromPanelId(''));
    }
}
