<?php

namespace App\Mail;

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

use App\Models\Service;

class OrderRequestApprove extends Mailable
{
    use Queueable, SerializesModels;

	public Service $so;
	public string $notes;

	/**
	 * Create a new message instance.
	 *
	 * @param Service $o
	 * @param string  $notes
	 */
    public function __construct(Service $o,string $notes='')
    {
		$this->so = $o;
		$this->notes = $notes;
    }

    /**
     * Build the message.
     */
    public function build()
    {
		Config::set('site',$this->so->site);

		// @todo This is not consistent with Cancel/Change Request
		switch ($this->so->product->category_lc) {
			case 'broadband': $subject = sprintf('%s: %s',$this->so->product->category_name,$this->so->type->service_address);
				break;

			case 'phone': $subject = sprintf('%s: %s',$this->so->product->category_name,$this->so->type->service_number);
				break;

			default:
				$subject = 'New Order Request';
		}

		return $this
			->markdown('mail.admin.order.approve')
			->subject($subject)
			->with(['site'=>$this->so->site]);
    }
}