<?php

declare(strict_types=1);

namespace Tests\Feature\Filament;

use App\Filament\Resources\Credits\CreditResource;
use App\Filament\Resources\FinancialOperations\FinancialOperationResource;
use App\Filament\Resources\Payments\PaymentResource;
use App\Models\Client;
use App\Models\Credit;
use App\Models\FinancialOperation;
use App\Models\Payment;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

/**
 * Títulos legibles de los recursos de Gestión de Créditos y Finanzas. Antes:
 * Créditos/Pagos mostraban el `id` desnudo y Operaciones Financieras apuntaba
 * `recordTitleAttribute` a una columna inexistente (`name`) → encabezado vacío.
 * Se prueban con modelos en memoria (setRelation) — sin tocar la BD.
 */
class CreditosFinanzasUxTest extends TestCase
{
    #[Test]
    public function credit_record_title_is_human_readable(): void
    {
        $credit = new Credit;
        $credit->id = 42;
        $credit->setRelation('client', new Client(['name' => 'Carlos Pérez']));

        $this->assertSame('Crédito #42 · Carlos Pérez', CreditResource::getRecordTitle($credit));
    }

    #[Test]
    public function payment_record_title_is_human_readable(): void
    {
        $credit = new Credit;
        $credit->setRelation('client', new Client(['name' => 'Ana Gómez']));

        $payment = new Payment;
        $payment->id = 7;
        $payment->setRelation('credit', $credit);

        $this->assertSame('Pago #7 · Ana Gómez', PaymentResource::getRecordTitle($payment));
    }

    #[Test]
    public function financial_operation_record_title_is_human_readable(): void
    {
        $op = new FinancialOperation;
        $op->id = 3;
        $op->operation_type = 'credit_renewal';

        $this->assertSame('Renovación #3', FinancialOperationResource::getRecordTitle($op));
    }
}
