import { describe, it, expect, vi, beforeEach } from 'vitest';
import { playlistService } from './playlistService';

describe('playlistService', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  describe('list', () => {
    it('should return list of playlists', async () => {
      const result = await playlistService.list();

      expect(result).toBeDefined();
      expect(result).toHaveProperty('playlists');
      expect(Array.isArray(result.playlists)).toBe(true);
      expect(result.playlists.length).toBeGreaterThan(0);
      expect(result.playlists[0]).toHaveProperty('id');
      expect(result.playlists[0]).toHaveProperty('title');
    });
  });

  describe('search', () => {
    it('should search playlists by query', async () => {
      const result = await playlistService.search('Cyberpunk');

      expect(result).toBeDefined();
      expect(result).toHaveProperty('playlists');
      expect(Array.isArray(result.playlists)).toBe(true);
    });

    it('should return empty array for no matches', async () => {
      const result = await playlistService.search('NonExistentPlaylist');

      expect(result).toBeDefined();
      expect(result.playlists).toEqual([]);
    });
  });

  describe('get', () => {
    it('should return playlist details', async () => {
      const result = await playlistService.get('1');

      expect(result).toBeDefined();
      expect(result).toHaveProperty('playlist');
      expect(result.playlist).toHaveProperty('id');
      expect(result.playlist).toHaveProperty('title');
    });
  });

  describe('create', () => {
    it('should create a new playlist', async () => {
      const newPlaylist = await playlistService.create({
        title: 'Test Playlist',
        isPublic: true,
      });

      expect(newPlaylist).toBeDefined();
      expect(newPlaylist).toHaveProperty('id');
      expect(newPlaylist.title).toBe('Test Playlist');
      expect(newPlaylist.trackCount).toBe(0);
      expect(newPlaylist.likes).toBe(0);
    });
  });

  describe('update', () => {
    it('should update a playlist', async () => {
      const result = await playlistService.update('1', {
        title: 'Updated Title',
      });

      // update returns Promise.resolve() which resolves to undefined
      expect(result).toBeUndefined();
    });
  });

  describe('delete', () => {
    it('should delete a playlist', async () => {
      const result = await playlistService.delete('1');

      // delete returns Promise.resolve() which resolves to undefined
      expect(result).toBeUndefined();
    });
  });

  describe('addTrack', () => {
    it('should add track to playlist', async () => {
      const result = await playlistService.addTrack();

      // addTrack returns Promise.resolve() which resolves to undefined
      expect(result).toBeUndefined();
    });
  });

  describe('removeTrack', () => {
    it('should remove track from playlist', async () => {
      const result = await playlistService.removeTrack();

      // removeTrack returns Promise.resolve() which resolves to undefined
      expect(result).toBeUndefined();
    });
  });

  describe('getRecommendations', () => {
    it('should return playlist recommendations', async () => {
      const result = await playlistService.getRecommendations();

      expect(result).toBeDefined();
      expect(result).toHaveProperty('tracks');
      expect(Array.isArray(result.tracks)).toBe(true);
    });
  });

  describe('createShareLink', () => {
    it('should create a share link', async () => {
      const result = await playlistService.createShareLink();

      expect(result).toBeDefined();
      expect(result).toHaveProperty('share_url');
    });
  });
});
