<?php

namespace App\Services\Paddle;

class PaddleCustomerPortalService
{
    public function __construct(private readonly PaddleClient $client) {}

    /**
     * @param  array{subscription_ids?: array<int, string>}  $options
     * @return array<string, mixed>
     */
    public function createSession(string $customerId, array $options = []): array
    {
        $payload = [];

        if (! empty($options['subscription_ids'])) {
            $payload['subscription_ids'] = array_values(
                array_filter($options['subscription_ids'], 'is_string')
            );
        }

        if ($payload === []) {
            $payload = (object) [];
        }

        return $this->client->post("/customers/{$customerId}/portal-sessions", $payload);
    }
}
