<?php

namespace App\Jobs;

use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;

class ProcessKycUploads implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(
        public User   $user,
        public string $avatarTemp,
        public string $dlFrontTemp,
        public string $dlBackTemp,
        public string $avatarName,
        public string $dlFrontName,
        public string $dlBackName,
        public array  $userData,
    ) {}

    public function handle(): void
    {
        Storage::disk('public')->move($this->avatarTemp,   "images/{$this->avatarName}");
        Storage::disk('public')->move($this->dlFrontTemp,  "images/{$this->dlFrontName}");
        Storage::disk('public')->move($this->dlBackTemp,   "images/{$this->dlBackName}");

        $this->user->update(array_merge($this->userData, [
            'avatar'     => $this->avatarName,
            'dl_front'   => $this->dlFrontName,
            'dl_back'    => $this->dlBackName,
            'kyc_status' => 2,
        ]));
    }
}