<?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 $service;
	public string $notes;

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

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

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

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

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

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