<?php

namespace App\Http\Controllers\Meet;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Meet\Concerns\ScopesToAccount;
use App\Models\Organization;
use App\Services\Meet\LicenseService;
use App\Services\Meet\OrganizationResolver;
use App\Services\Meet\UsageMeteringService;
use Illuminate\Http\Request;
use Illuminate\View\View;

class AdminController extends Controller
{
    use ScopesToAccount;

    public function __construct(
        protected UsageMeteringService $metering,
        protected LicenseService $licenses,
    ) {}

    public function usage(Request $request): View
    {
        $this->authorizeAbility($request, 'meetings.manage');
        $organization = $this->organization($request);
        $branchId = app(OrganizationResolver::class)->branchScope($this->member($request));

        $summary = $this->metering->usageSummary($organization, $branchId);
        $costs = $this->metering->estimatedCostGhs($summary);
        $quotas = $this->licenses->quotas($organization);
        $tier = $organization->license_tier ?? 'standard';
        $billing = app(\App\Services\Meet\MeetBillingService::class);

        return view('meet.admin.usage', compact('organization', 'summary', 'costs', 'quotas', 'tier', 'billing'));
    }
}
