<?php

namespace App\Mail;

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

class MonthlyReport extends Mailable
{
    use Queueable, SerializesModels;

    private $year, $month, $organisation_id, $token;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($_year, $_month, $_organisation_id, $_token)
    {
        $this->year = $_year;
        $this->month = $_month;
        $this->organisation_id = $_organisation_id;
        $this->token = $_token;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('mail.html.report-monthly')
            ->subject('Monthly Mitigation Report')
            ->with([
                'month' => Carbon::parse("$this->year-01-01")->addMonths($this->month-1)->startOfDay()->format('F Y'),
                'url' => url("api/guest/report/download/$this->token")
            ]);
    }
}
