<?php

declare(strict_types=1);

namespace App\Services;

use App\Models\SubscriptionConfigSelection;
use Illuminate\Support\Collection;
use Laravel\Cashier\Subscription;

class ConfigSelectionService
{
    public function getSelections(Subscription $subscription): Collection
    {
        return SubscriptionConfigSelection::query()
            ->where('subscription_id', $subscription->id)
            ->with(['option', 'value'])
            ->get();
    }

    public function totalConfigPrice(Subscription $subscription, string $cycle): float
    {
        return (float) SubscriptionConfigSelection::query()
            ->where('subscription_id', $subscription->id)
            ->where('billing_cycle', $cycle)
            ->sum('locked_price');
    }

    public function totalHourlyPrice(Subscription $subscription): float
    {
        return (float) SubscriptionConfigSelection::query()
            ->where('subscription_id', $subscription->id)
            ->whereNotNull('locked_hourly_price')
            ->sum('locked_hourly_price');
    }
}
