<?php

namespace App\Mail;

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

class EstimateDetail extends Mailable
{
    use Queueable, SerializesModels;
	
	public $estimate;
	public $company;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(Estimate $estimate)
    {
		
        $this->estimate = $estimate;
		$this->company = \Auth::user()->employee->company;
		
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
		
		$message = $this->subject('Estimate')->from($this->company->contacts['email'], $this->company->name)->subject($this->subject)->view('emails.estimate_detail');	
		
		if (count($this->estimate->attachments)) {
			foreach ($this->estimate->attachments as $attachment) {
				$message->attach($attachment['url']);
			}
		}
		
		return $message;
		
    }
}
