<?php

namespace Tests\Feature;

use Mtc\Plugins\WeightVerification\Src\Models\WeightVerification;
use Tests\TestCase;

class WeightVerificationModelTest extends TestCase
{
    public function test_action_required_only_for_pending_and_resubmit(): void
    {
        $this->assertTrue($this->withStatus(WeightVerification::STATUS_PENDING)->action_required);
        $this->assertTrue($this->withStatus(WeightVerification::STATUS_RESUBMIT_REQUIRED)->action_required);
        $this->assertFalse($this->withStatus(WeightVerification::STATUS_SUBMITTED)->action_required);
        $this->assertFalse($this->withStatus(WeightVerification::STATUS_APPROVED)->action_required);
    }

    public function test_is_submitted_for_submitted_and_approved(): void
    {
        $this->assertTrue($this->withStatus(WeightVerification::STATUS_SUBMITTED)->is_submitted);
        $this->assertTrue($this->withStatus(WeightVerification::STATUS_APPROVED)->is_submitted);
        $this->assertFalse($this->withStatus(WeightVerification::STATUS_PENDING)->is_submitted);
        $this->assertFalse($this->withStatus(WeightVerification::STATUS_RESUBMIT_REQUIRED)->is_submitted);
    }

    public function test_status_label_is_humanised(): void
    {
        $this->assertSame('Resubmit Required', $this->withStatus(WeightVerification::STATUS_RESUBMIT_REQUIRED)->status_label);
        $this->assertSame('Submitted', $this->withStatus(WeightVerification::STATUS_SUBMITTED)->status_label);
    }

    public function test_photo_urls_are_null_without_files_and_root_relative_with_files(): void
    {
        $verification = $this->withStatus(WeightVerification::STATUS_PENDING);
        $this->assertNull($verification->front_url);
        $this->assertNull($verification->side_url);

        $verification->front_file_id = 7;
        $verification->side_file_id = 9;

        // Root-relative on purpose so it resolves against the origin from the
        // legacy admin bootstrap (not the current script path).
        $this->assertSame('/admin/files/get/7', $verification->front_url);
        $this->assertSame('/admin/files/get/9', $verification->side_url);
    }

    private function withStatus(string $status): WeightVerification
    {
        return new WeightVerification(['status' => $status]);
    }
}
