<?php

namespace App\Http\Resources;

use App\Models\ProviderBankAccount;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Http\Resources\Json\JsonResource;

class ProviderBankAccountResource extends JsonResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id'                  => $this->id,
            'provider_id'         => $this->provider_id,
            'bank_id'             => $this->bank_id,
            'bank_code'           => $this->bank_code,
            'bank_name'           => $this->bank?->name ?? $this->bank_name,
            'holder_name'         => $this->holder_name,
            'holder_document'     => $this->holder_document,
            'type'                => $this->type,
            'branch_number'       => $this->branch_number,
            'branch_check_digit'  => $this->branch_check_digit,
            'account_number'      => $this->account_number,
            'account_check_digit' => $this->account_check_digit,
            'is_primary'          => $this->is_primary,
            'is_active'           => $this->is_active,
            'synced'              => $this->isSyncedWithGateway(),
            'created_at'          => $this->created_at?->format('d/m/Y H:i'),
            'updated_at'          => $this->updated_at?->format('d/m/Y H:i'),
        ];
    }

    /**
     * @param \Illuminate\Database\Eloquent\Collection<ProviderBankAccount> $resource
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<ProviderBankAccountResource>
     */
    public static function collection($resource): AnonymousResourceCollection
    {
        return parent::collection($resource);
    }
}
