<?php

namespace App\Services\Mail;

use App\Models\GeneratedReport;
use Illuminate\Support\Str;

class ReportEmailBuilder
{
    public function subject(GeneratedReport $report, ?string $customSubject = null): string
    {
        if (filled($customSubject)) {
            return (string) $customSubject;
        }

        $type = [
            'daily' => 'Günlük',
            'weekly' => 'Haftalık',
            'monthly' => 'Aylık',
            'custom' => 'Özel Tarih',
        ][$report->report_type] ?? Str::headline($report->report_type);

        $clientName = $report->client?->company_name ?? 'Müşteri';
        $range = $report->date_from?->format('d.m.Y') . ' - ' . $report->date_to?->format('d.m.Y');

        return $clientName . ' | ' . $type . ' Reklam Raporu | ' . $range;
    }

    /**
     * @return array<string, mixed>
     */
    public function viewData(GeneratedReport $report, ?string $note = null): array
    {
        $overview = $report->summary['overview'] ?? [];
        $notes = $report->summary['notes'] ?? [];

        return [
            'report' => $report,
            'client' => $report->client,
            'overview' => $overview,
            'notes' => $notes,
            'customNote' => $note,
        ];
    }
}
