<?php

namespace App\Services;

use App\Repositories\ReportsRepository;
use Illuminate\Support\Facades\Storage;

class ReportsService
{
    protected ReportsRepository $repo;

    protected ActivityLogService $activityLog;

    public function __construct(ReportsRepository $repo, ActivityLogService $activityLog)
    {
        $this->repo = $repo;
        $this->activityLog = $activityLog;
    }

    public function revenueByMonth(array $filters = [])
    {
        return $this->repo->revenueByMonth($filters['from'] ?? null, $filters['to'] ?? null);
    }

    public function customersOverview()
    {
        return $this->repo->customersOverview();
    }

    public function storeExportCsv(string $filename, string $content): string
    {
        $path = 'exports/'.$filename;
        Storage::put($path, $content);

        return $path;
    }

    public function logExport(string $type, array $meta = [])
    {
        $this->activityLog->log([
            'action' => 'report.export',
            'description' => 'Exported '.$type.' report',
            'metadata' => $meta,
        ]);
    }
}
