<?php

namespace App\Mail;

use App\Models\Core\Mail\MailTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Spatie\MailTemplates\TemplateMailable;

class AlerteStock extends TemplateMailable
{
    use Queueable, SerializesModels;

    public $subject;

    public $article;

    public $offre;

    public $stock_restant;

    public $seuil;

    public $lien_article;

    public $lien_offre;

    protected static $templateModelClass = MailTemplate::class;

    public function __construct($offer)
    {
        $this->article = $offer->article->name ?? 'Article #'.$offer->article_id;
        $this->offre = $offer->id;
        $this->stock_restant = $offer->stock_current;
        $this->seuil = $offer->minimum_ondemand;
        $this->lien_article = url('/Admin/Shop/Articles/edit/'.$offer->article_id);
        $this->lien_offre = url('/Admin/Shop/Offers/edit/'.$offer->id);
    }

    public function envelope()
    {
        return new Envelope(
            from: new Address('boutique@jardinenvie.com', 'Jardin\'en\'Vie'),
            subject: $this->subject,
        );
    }
}
