<?php

namespace Tests\Feature\Receipt;

use App\Models\Accident;
use App\Models\LogList;
use App\Models\User;
use App\Services\PaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Mockery\MockInterface;
use Tests\TestCase;

class CallPaymentStatusTest extends TestCase
{
    use RefreshDatabase;
    /**
     * A basic feature test example.
     */
    public function test_payment_status_will_return_by_the_service(): void
    {
        $user = User::factory()->create();

        LogList::factory()->create(['log_unique_code' => 1130]);

        $accident = Accident::factory()->create([
            'final_amount' => $this->faker->numerify('##')
        ]);

        $this->mock(PaymentService::class, function (MockInterface $mock) {
            $mock->shouldReceive('callPaymentStatusBillApi')->andReturn(json_encode(['isPayed' => 1]));
        });

        $response = $this->actingAs($user)->postJson("/v2/receipt/call-payment-status/{$accident->id}");

        $response->assertStatus(200)
            ->assertExactJson([
                "accident_date" => $accident->accident_date,
                "accident_time" => $accident->accident_time,
                "accident_type" => $accident->accident_type,
                "accident_type_fa" => $accident->accident_type_fa,
                "axis_name" => $accident->axis_name,
                "bill_code" => $accident->bill_code,
                "city_fa" => $accident->city_fa,
                "city_id" => $accident->city_id,
                "created_at" => $accident->created_at,
                "damage_picture1" => $accident->damage_picture1,
                "damage_picture2" => $accident->damage_picture2,
                "deposit_daghi_amount" => 0,
                "deposit_daghi_image" => $accident->deposit_daghi_image,
                "deposit_date" => $accident->deposit_date,
                "deposit_insurance_amount" => 0,
                "deposit_insurance_image" => $accident->deposit_insurance_image,
                "driver_name" => $accident->driver_name,
                "driver_national_code" => $accident->driver_national_code,
                "driver_phone_number" => $accident->driver_phone_number,
                "final_amount" => $accident->final_amount,
                "id" => $accident->id,
                "lat" => $accident->lat,
                "lng" => $accident->lng,
                "ojrate_nasb" => $accident->ojrate_nasb,
                "plaque" => $accident->plaque,
                "police_file" => $accident->police_file,
                "police_file_date" => $accident->police_file_date,
                "police_serial" => $accident->police_serial,
                "province_fa" => $accident->province_fa,
                "province_id" => $accident->province_id,
                "report_base" => $accident->report_base,
                "status" => 0,
                "status_fa" => $accident->status_fa,
                "status_history" => '0',
                "sum" => $accident->sum,
                "support_description" => $accident->support_description,
                "updated_at" => $accident->updated_at,
                "user_id" => $accident->user_id,
                "way_id" => $accident->way_id
            ]);
    }

    public function test_payment_status_works_properly(): void
    {
        $user = User::factory()->create();

        LogList::factory()->create(['log_unique_code' => 1130]);

        $accident = Accident::factory()->create([
            'final_amount' => $this->faker->numerify('0')
        ]);

        $response = $this->actingAs($user)->postJson("/v2/receipt/call-payment-status/{$accident->id}");

        $response->assertStatus(200)
            ->assertExactJson([
                "accident_date" => $accident->accident_date,
                "accident_time" => $accident->accident_time,
                "accident_type" => $accident->accident_type,
                "accident_type_fa" => $accident->accident_type_fa,
                "axis_name" => $accident->axis_name,
                "bill_code" => $accident->bill_code,
                "city_fa" => $accident->city_fa,
                "city_id" => $accident->city_id,
                "created_at" => $accident->created_at,
                "damage_picture1" => $accident->damage_picture1,
                "damage_picture2" => $accident->damage_picture2,
                "deposit_daghi_amount" => 0,
                "deposit_daghi_image" => $accident->deposit_daghi_image,
                "deposit_date" => $accident->deposit_date,
                "deposit_insurance_amount" => 0,
                "deposit_insurance_image" => $accident->deposit_insurance_image,
                "driver_name" => $accident->driver_name,
                "driver_national_code" => $accident->driver_national_code,
                "driver_phone_number" => $accident->driver_phone_number,
                "final_amount" => $accident->final_amount,
                "id" => $accident->id,
                "lat" => $accident->lat,
                "lng" => $accident->lng,
                "ojrate_nasb" => $accident->ojrate_nasb,
                "plaque" => $accident->plaque,
                "police_file" => $accident->police_file,
                "police_file_date" => $accident->police_file_date,
                "police_serial" => $accident->police_serial,
                "province_fa" => $accident->province_fa,
                "province_id" => $accident->province_id,
                "report_base" => $accident->report_base,
                "status" => 0,
                "status_fa" => $accident->status_fa,
                "status_history" => '0',
                "sum" => $accident->sum,
                "support_description" => $accident->support_description,
                "updated_at" => $accident->updated_at,
                "user_id" => $accident->user_id,
                "way_id" => $accident->way_id
            ]);
    }
}
