<?php

namespace App\Services;

use App\Helpers\AmountInWords;
use App\Helpers\CompanyMedia;
use App\Helpers\CompanySettings;
use App\Helpers\PaymentDocumentSettings;
use App\Models\Company;
use App\Models\Payment;

class PaymentDocumentPresenter
{
    /**
     * @return array<string, mixed>
     */
    public function displayData(Payment $payment): array
    {
        $payment->load(['allocations', 'customer', 'vendor']);
        $company = Company::findOrFail($payment->company_id);
        $settings = CompanySettings::forCompany($company->id);
        $docSettings = PaymentDocumentSettings::forCompany($company->id);
        $kindMeta = $payment->kindMeta();
        $party = $payment->isReceived() ? $payment->customer : $payment->vendor;

        return [
            'payment' => $payment,
            'party' => $party,
            'company' => $company,
            'settings' => $settings,
            'docSettings' => $docSettings,
            'kindMeta' => $kindMeta,
            'paymentTitle' => $kindMeta['title'] ?? 'PAYMENT',
            'amountLabel' => $kindMeta['amount_label'] ?? 'Amount',
            'amountInWords' => AmountInWords::rupees((float) $payment->amount),
            'documentCopies' => [
                'original' => 'Original Copy',
                'duplicate' => 'Duplicate Copy',
            ],
            'logoSrc' => CompanyMedia::imageSource($company->logo_path),
            'signatureSrc' => CompanyMedia::imageSource($company->signature_image_path),
        ];
    }
}
