<?php

namespace App\Http\Resources;

use App\Models\NomineeDocument;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @mixin NomineeDocument
 */
class NomineeDocumentResource extends JsonResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        $customerId = $this->nominee?->customer_id ?? $this->nominee()->value('customer_id');

        return [
            'id' => $this->id,
            'originalName' => $this->original_name,
            'mimeType' => $this->mime_type,
            'size' => $this->size,
            'url' => '/api/customers/'.$customerId.'/nominee/documents/'.$this->id.'/file',
            'uploadedBy' => $this->uploaded_by,
            'createdAt' => $this->created_at?->toIso8601String(),
        ];
    }
}
