<?php

namespace App\Classes\Notifications;

use App\Models\Booking;
use App\Models\User;
use App\Models\File;
use App\Models\UserEmailVerification;
use Illuminate\Notifications\Messages\MailMessage;

class PaymentProofUploadedEmail extends AbstractEmail
{

    /** @var User */
    private $user;

    /** @var Booking */
    private $booking;

    /** @var File */
    private $file;

    /**
     * UserVerificationEmail constructor.
     * @param User $user
     * @param UserEmailVerification $attempt
     */
    public function __construct(User $user, Booking $booking, File $file)
    {
        $this->user = $user;
        $this->booking = $booking;
        $this->file = $file;
    }


    public function toMail()
    {
        $attachedFile = null;
        $file_info = $this->file->getFileAttribute($this->file)->file->file_info;
        foreach ($file_info as $fileCount => $fileVal) {
            if (isset($fileVal->original)) {
                $file_path = $fileVal->original->file;
                $attachedFile = storage_path('app/documents/' . $file_path);
            }
        }

        return (new MailMessage)
            ->subject('Transfer Completed (REF: ' . $this->booking->marking . ')')
            // ->attach($attachedFile) // todo-new: add attachement
            ->view('emails.accounts.payment_proof_email', ['user' => $this->user, 'booking' => $this->booking]);
    }


}
