<?php

namespace App\Mail;

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

class QuarterlyReport extends Mailable
{
    use Queueable, SerializesModels;

    private $year, $quarter, $organisation_id, $token;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $start = Carbon::parse("$this->year-01-01")->startOfYear()->addMonths(($this->quarter-1) * 3)->startOfDay();
        $end = Carbon::parse("$this->year-01-01")->startOfYear()->addMonths((($this->quarter-1) * 3) + 3)->subDay()->endOfDay();
        
        return $this->view('mail.html.report-quarterly')
            ->subject('Quarterly Mitigation Report')
            ->with([
                'quarter' => $this->quarter,
                'start' => $start,
                'end' => $end,
                'url' => url("api/guest/report/download/$this->token")
            ]);
    }
}
