<?php

declare(strict_types=1);

return [
    'storage_root' => env('SKINBASE_STORAGE_ROOT', storage_path('app/artworks')),

    'local_originals_root' => env('ARTWORKS_LOCAL_ORIGINALS_ROOT', storage_path('app/originals/artworks')),

    'readonly_backup_originals_root' => env('ARTWORKS_READONLY_BACKUP_ORIGINALS_ROOT', '/opt/www/virtual/files/cdn/artworks/original'),

    'object_storage' => [
        'disk' => env('ARTWORKS_OBJECT_DISK', 's3'),
        'prefix' => env('ARTWORKS_OBJECT_PREFIX', 'artworks'),
    ],

    'featured_prefix' => env('ARTWORKS_FEATURED_OBJECT_PREFIX', 'artworks/featured'),

    'paths' => [
        'tmp'      => 'tmp',
        'quarantine' => 'quarantine',
        'original' => 'original',
        'xs'       => 'xs',
        'sm'       => 'sm',
        'md'       => 'md',
        'lg'       => 'lg',
        'xl'       => 'xl',
        'sq'       => 'sq',
    ],

    'max_size_mb' => 50,
    'max_archive_size_mb' => 200,
    'max_pixels' => 12000,

    'allowed_mimes' => [
        'image/jpeg',
        'image/png',
        'image/webp',
    ],

    'allow_gif' => env('UPLOAD_ALLOW_GIF', false),

    'allowed_archive_mimes' => [
        'application/zip',
        'application/x-zip-compressed',
        'application/x-rar-compressed',
        'application/vnd.rar',
        'application/x-7z-compressed',
        'application/x-tar',
        'application/gzip',
        'application/x-gzip',
        'application/octet-stream',
    ],

    'derivatives' => [
        'xs' => ['max' => 320],
        'sm' => ['max' => 680],
        'md' => ['max' => 1024],
        'lg' => ['max' => 1920],
        'xl' => ['max' => 2560],
        'sq' => ['size' => 512],
    ],

    'featured_variants' => [
        'mobile_xs' => ['width' => 400, 'height' => 400, 'quality' => 76, 'media' => '(max-width: 479px)', 'sizes' => '100vw'],
        'mobile_sm' => ['width' => 640, 'height' => 640, 'quality' => 78, 'media' => '(max-width: 639px)', 'sizes' => '100vw'],
        'mobile' => ['width' => 900, 'height' => 900, 'quality' => 80, 'media' => '(max-width: 767px)', 'sizes' => '100vw'],
        'tablet' => ['width' => 1280, 'height' => 900, 'quality' => 82, 'media' => '(max-width: 1279px)', 'sizes' => '100vw'],
        'desktop' => ['width' => 1600, 'height' => 900, 'quality' => 84, 'media' => '(max-width: 1599px)', 'sizes' => '100vw'],
        'desktop_xl' => ['width' => 2200, 'height' => 1238, 'quality' => 86, 'media' => '(min-width: 1600px)', 'sizes' => '100vw'],
    ],

    'featured_thumbnails' => [
        'queue' => env('ARTWORKS_FEATURED_THUMBNAIL_QUEUE', 'default'),
    ],

    'square_thumbnails' => [
        'width' => env('UPLOAD_SQ_WIDTH', 512),
        'height' => env('UPLOAD_SQ_HEIGHT', 512),
        'quality' => env('UPLOAD_SQ_QUALITY', 82),
        'smart_crop' => env('UPLOAD_SQ_SMART_CROP', true),
        'padding_ratio' => env('UPLOAD_SQ_PADDING_RATIO', 0.18),
        'allow_upscale' => env('UPLOAD_SQ_ALLOW_UPSCALE', false),
        'fallback_strategy' => env('UPLOAD_SQ_FALLBACK_STRATEGY', 'center'),
        'log' => env('UPLOAD_SQ_LOG', false),
        'preview_size' => env('UPLOAD_PREVIEW_SQ_SIZE', 320),
        'subject_detector' => [
            'preferred_labels' => [
                'person',
                'portrait',
                'face',
                'human',
                'animal',
                'lion',
                'dog',
                'cat',
                'bird',
            ],
        ],
        'saliency' => [
            'sample_max_dimension' => env('UPLOAD_SQ_SALIENCY_SAMPLE_MAX', 96),
            'min_total_energy' => env('UPLOAD_SQ_SALIENCY_MIN_TOTAL', 2400),
            'window_ratios' => [0.55, 0.7, 0.82, 1.0],
        ],
    ],

    'quality' => 85,

    'queue_derivatives' => env('UPLOAD_QUEUE_DERIVATIVES', false),

    'rate_limits' => [
        'decay_minutes' => env('UPLOAD_RATE_DECAY_MINUTES', 1),
        'init' => [
            'per_user' => env('UPLOAD_RATE_INIT_USER', 10),
            'per_ip' => env('UPLOAD_RATE_INIT_IP', 30),
        ],
        'chunk' => [
            'per_user' => env('UPLOAD_RATE_CHUNK_USER', 180),
            'per_ip' => env('UPLOAD_RATE_CHUNK_IP', 360),
        ],
        'finish' => [
            'per_user' => env('UPLOAD_RATE_FINISH_USER', 6),
            'per_ip' => env('UPLOAD_RATE_FINISH_IP', 12),
        ],
        'status' => [
            'per_user' => env('UPLOAD_RATE_STATUS_USER', 60),
            'per_ip' => env('UPLOAD_RATE_STATUS_IP', 120),
        ],
    ],

    'quotas' => [
        'max_active_sessions' => env('UPLOAD_MAX_ACTIVE_SESSIONS', 100),
        'max_daily_sessions' => env('UPLOAD_MAX_DAILY_SESSIONS', 250),
    ],

    'draft_quota' => [
        'max_drafts_per_user' => env('SKINBASE_MAX_DRAFTS', 10),
        'max_draft_storage_mb_per_user' => env('SKINBASE_MAX_DRAFT_STORAGE_MB', 1024),
        'duplicate_hash_policy' => env('SKINBASE_DUPLICATE_HASH_POLICY', 'block'), // block|warn
    ],

    'tokens' => [
        'ttl_minutes' => env('UPLOAD_TOKEN_TTL_MINUTES', 60),
    ],

    'chunk' => [
        'max_bytes' => env('UPLOAD_CHUNK_MAX_BYTES', 5242880),
        'lock_seconds' => env('UPLOAD_CHUNK_LOCK_SECONDS', 10),
        'lock_wait_seconds' => env('UPLOAD_CHUNK_LOCK_WAIT_SECONDS', 5),
        'request_timeout_ms' => env('UPLOAD_CHUNK_REQUEST_TIMEOUT_MS', 45000),
    ],

    'scan' => [
        'enabled' => env('UPLOAD_SCAN_ENABLED', false),
        'command' => env('UPLOAD_SCAN_COMMAND', []),
    ],
];
