<?php

namespace App\Mail;

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

class Email extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * The demo object instance.
     *
     * @var Demo
     */
    public $demo;
    public $Tipo;
    public $_from;
    public $plantilla;
    public $plantilla_plano;
    public $asunto;


    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($demo, $Tipo)
    {
        $this->demo = $demo;
        $this->Tipo = $Tipo;

    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {

        return $this->from($this->_from)
            ->view($this->plantilla)
            ->text($this->plantilla_plano)
            ->subject($this->asunto)
            ->with(
                [
                    'testVarOne' => '1',
                    'testVarTwo' => '2',
                ]);
    }

    public function ConfigurarFrom()
    {

        //dd($existing);

        $this->_from = 'info@ventanillaunicaubate.com';
        $this->plantilla = 'mails.email';
        $this->plantilla_plano = 'mails.demo_plain';
        $this->asunto = 'Novedad en su radicado';

        if ($this->Tipo == 'Registro') {
            
            $this->_from = 'informacion@ventanillaunicaubate.com';
            $this->plantilla = 'mails.validar';
            $this->plantilla_plano = 'mails.demo_validar';
            $this->asunto = 'Verifique su cuenta';

            $existing = config('mail');
            $new = array_merge(
                $existing, [
                    'from' => [
                        'address' => 'informacion@ventanillaunicaubate.com',
                        'name' => 'Informacion',
                    ],
                ]);

            config(['mail' => $new]);
        }else if ($this->Tipo == 'Reset') {

            $this->_from = 'informacion@ventanillaunicaubate.com';
            $this->plantilla = 'mails.reset';
            $this->plantilla_plano = 'mails.demo_reset';
            $this->asunto = 'Restaurar su contraseña';

            $existing = config('mail');
            $new = array_merge(
                $existing, [
                    'from' => [
                        'address' => 'informacion@ventanillaunicaubate.com',
                        'name' => 'Informacion',
                    ],
                ]);

            config(['mail' => $new]);
        }

        return $this;

    }

}
