<?php

namespace App\Classes\Notifications;


use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\PackingList;
use App\Models\PasswordReset;
use App\Models\User;
use Illuminate\Notifications\Messages\MailMessage;

class ShipmentDepartureEmail extends AbstractEmail
{

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

    /** @var PackingList */
    private $packingList;

    /**
     * @param User $user
     * @param PackingList $packingList
     */
    public function __construct(User $user, PackingList $packingList)
    {
        $this->user = $user;
        $this->packingList = $packingList;
    }



    public function toMail()
    {
        $invoice = $this->packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::APPROVED)->first();

        if(!$invoice) return false;

        $invoiceDocument = $invoice->documents()->first()->files;


        return (new MailMessage)
            ->subject('Your packages are on the way to malaysia - Invoice pending payment for order no.'. $this->packingList->owner->reference)
            ->attach(Storage::disk('documents')->get($invoiceDocument->file->file_info->original->file), [
                'as' => 'name.pdf',
                'mime' => 'application/pdf',
            ])->bcc(['email_test@cief-malaysia.com'])->view('emails.shipment.ETD', ['user' => $this->user, 'packingList' => $this->packingList]);
    }


}
