<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;

class AdminAnalyticsReportMail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public function __construct(
        public string $frequency,
        public Carbon $start,
        public Carbon $end,
        public array $rows,
        public array $totals,
    ) {
    }

    public function envelope(): Envelope
    {
        $title = $this->frequency === 'weekly' ? 'Weekly' : 'Daily';

        return new Envelope(
            subject: "{$title} VTU Analytics Report (".$this->end->toDateString().')',
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.admin.analytics-report',
            with: [
                'frequency' => $this->frequency,
                'start' => $this->start,
                'end' => $this->end,
                'rows' => $this->rows,
                'totals' => $this->totals,
            ],
        );
    }

    public function attachments(): array
    {
        return [];
    }
}
