<?php

namespace App\Mail;

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

class WeeklyReport extends Mailable
{
    use Queueable, SerializesModels;

    private $year, $week, $organisation_id, $token;

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

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