<?php

declare(strict_types=1);

use apexl\Config\ConfigurationInterface;
use apexl\Io\modules\mirrorS3\Dto\S3ConfigDto;
use Aws\S3\S3Client;
use function DI\factory;

return [
    S3ConfigDto::class => factory(fn(ConfigurationInterface $config) => new S3ConfigDto(
        bucket: $config->get('mirror.s3.bucket'),
        version: $config->get('mirror.s3.version'),
        endpoint: $config->get('mirror.s3.endpoint'),
        use_path_style_endpoint: $config->get('mirror.s3.use_path_style_endpoint'),
        key: $config->get('mirror.s3.credentials.key'),
        secret: $config->get('mirror.s3.credentials.secret'),
    )),

    S3Client::class => factory(
        fn(S3ConfigDto $s3Config) => new S3Client([
            'version' => $s3Config->version,
            'region' => 'us-east-1', #Leave this, regardless of actual region; this is a Digital Ocean quirk(tm)
            'endpoint' => $s3Config->endpoint,
            'use_path_style_endpoint' => $s3Config->use_path_style_endpoint,
            'credentials' => [
                'key' => $s3Config->key,
                'secret' => $s3Config->secret,
            ],
        ])
    ),
];
