<?php

namespace App\Http\Controllers\Concerns;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

trait ManagesPartnerUploads
{
    protected function storePartnerUploads(Request $request, array $data, ?string $existingPhoto = null, ?string $existingIdProof = null): array
    {
        if ($request->hasFile('photo')) {
            if ($existingPhoto) {
                Storage::disk('public')->delete($existingPhoto);
            }
            $data['photo_path'] = $request->file('photo')->store('partners/photos', 'public');
        }

        if ($request->hasFile('id_proof')) {
            if ($existingIdProof) {
                Storage::disk('public')->delete($existingIdProof);
            }
            $data['id_proof_path'] = $request->file('id_proof')->store('partners/id-proofs', 'public');
        }

        return $data;
    }

    protected function profilePayload(Request $request, array $fields): array
    {
        return $request->only($fields);
    }
}
