<?php

namespace App\Http\Controllers\Portal;

use App\Http\Controllers\Controller;
use App\Services\CurrencyResolver;
use App\Services\PricingService;
use Illuminate\Http\Request;

class StoreController extends Controller
{
    public function __construct(private readonly PricingService $pricing, private readonly CurrencyResolver $currencyResolver) {}

    public function index(Request $request)
    {
        $currency = $this->currencyResolver->resolve($request)['currency'];
        $groups = $this->pricing->productGroups($currency);
        $defaultGroup = $groups[0]['slug'] ?? 'web-hosting';

        return redirect()->route('checkout.index', ['group' => $defaultGroup]);
    }

    public function group(Request $request, string $group = 'web-hosting')
    {
        return redirect()->route('checkout.index', ['group' => $group]);
    }

    public function hosting(Request $request)
    {
        return $this->group($request, 'web-hosting');
    }

    public function email(Request $request)
    {
        return $this->group($request, 'business-email');
    }
}
