<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class UserDeletedMail extends Mailable implements ShouldQueue
{
    use Queueable;
    use SerializesModels;

    protected $result;

    /**
     * Create a new message instance.
     */
    public function __construct($result)
    {
        $this->result = $result;
        $this->locale = $result['deletedUser']->lang_preference ?? config('app.locale', 'en');
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        // Set application locale for this email
        app()->setLocale($this->locale);

        return $this
                ->from(timebank_config('mail.system_admin.email'), timebank_config('mail.system_admin.name'))
                ->subject(trans('messages.Your_profile_has_been_deleted', [], $this->locale))
                ->view('emails.administration.user-deleted')
                ->with([
                    'name' => $this->result['deletedUser']->name,
                    'full_name' => $this->result['deletedUser']->full_name,
                    'deletedMail' => $this->result['mail'],
                    'time' => $this->result['time'],
                    'balanceHandlingOption' => $this->result['balanceHandlingOption'] ?? null,
                    'totalBalance' => $this->result['totalBalance'] ?? 0,
                    'donationAccountName' => $this->result['donationAccountName'] ?? null,
                    'donationOrganizationName' => $this->result['donationOrganizationName'] ?? null,
                    'autoDeleted' => $this->result['autoDeleted'] ?? false,
                    'daysNotLoggedIn' => $this->result['daysNotLoggedIn'] ?? null,
                    'daysAfterInactive' => $this->result['daysAfterInactive'] ?? null,
                    'totalDaysToDelete' => $this->result['totalDaysToDelete'] ?? null,
                    'gracePeriodDays' => $this->result['gracePeriodDays'] ?? timebank_config('delete_profile.grace_period_days', 30),
                ]);
    }


}
