<?php

declare(strict_types=1);

use App\Domain\PreSave\ValueObjects\StreamingPlatform;

describe('StreamingPlatform', function () {
    describe('display names', function () {
        it('returns correct display name for SPOTIFY', function () {
            $name = StreamingPlatform::SPOTIFY->getDisplayName();
            expect(str_contains($name, 'Spotify'))->toBeTrue();
        });

        it('returns correct display name for TIDAL', function () {
            $name = StreamingPlatform::TIDAL->getDisplayName();
            expect(str_contains($name, 'Tidal'))->toBeTrue();
        });

        it('returns correct display name for APPLE_MUSIC', function () {
            $name = StreamingPlatform::APPLE_MUSIC->getDisplayName();
            expect(str_contains($name, 'Apple Music'))->toBeTrue();
        });

        it('returns correct display name for DEEZER', function () {
            $name = StreamingPlatform::DEEZER->getDisplayName();
            expect(str_contains($name, 'Deezer'))->toBeTrue();
        });

        it('returns correct display name for YOUTUBE_MUSIC', function () {
            $name = StreamingPlatform::YOUTUBE_MUSIC->getDisplayName();
            expect(str_contains($name, 'YouTube Music'))->toBeTrue();
        });
    });

    describe('OAuth provider mapping', function () {
        it('returns OAuth provider name matching enum value', function () {
            expect(str_contains(StreamingPlatform::SPOTIFY->getOAuthProvider(), 'spotify'))->toBeTrue();
            expect(str_contains(StreamingPlatform::TIDAL->getOAuthProvider(), 'tidal'))->toBeTrue();
            expect(str_contains(StreamingPlatform::APPLE_MUSIC->getOAuthProvider(), 'apple_music'))->toBeTrue();
        });
    });

    describe('platform support status', function () {
        it('identifies SPOTIFY as supported', function () {
            expect(StreamingPlatform::SPOTIFY->isSupported())->toBeTrue();
        });

        it('identifies TIDAL as not yet supported', function () {
            expect(StreamingPlatform::TIDAL->isSupported())->toBeFalse();
        });

        it('identifies APPLE_MUSIC as not yet supported', function () {
            expect(StreamingPlatform::APPLE_MUSIC->isSupported())->toBeFalse();
        });

        it('identifies DEEZER as not yet supported', function () {
            expect(StreamingPlatform::DEEZER->isSupported())->toBeFalse();
        });

        it('identifies YOUTUBE_MUSIC as not yet supported', function () {
            expect(StreamingPlatform::YOUTUBE_MUSIC->isSupported())->toBeFalse();
        });
    });

    describe('supported platforms list', function () {
        it('returns only supported platforms', function () {
            $supported = StreamingPlatform::supported();

            $supportedCount = 0;
            foreach ($supported as $platform) {
                if ($platform === StreamingPlatform::SPOTIFY) {
                    $supportedCount++;
                }
            }

            expect($supportedCount)->toBeGreaterThan(0);
        });

        it('filters out unsupported platforms', function () {
            $supported = StreamingPlatform::supported();

            $hasUnsupported = false;
            foreach ($supported as $platform) {
                if (!$platform->isSupported()) {
                    $hasUnsupported = true;
                }
            }

            expect($hasUnsupported)->toBeFalse();
        });
    });

    describe('enum cases', function () {
        it('has all expected platform cases', function () {
            $cases = StreamingPlatform::cases();
            $caseValues = array_map(fn($case) => $case->value, $cases);

            expect(in_array('spotify', $caseValues))->toBeTrue();
            expect(in_array('tidal', $caseValues))->toBeTrue();
            expect(in_array('apple_music', $caseValues))->toBeTrue();
            expect(in_array('deezer', $caseValues))->toBeTrue();
            expect(in_array('youtube_music', $caseValues))->toBeTrue();
        });
    });
});
