using Harmonia.Core.Models;
using Harmonia.Core.Playlists;
using NSubstitute;
using Shouldly;
using System.ComponentModel;

namespace Harmonia.Tests;

public class PlaylistTests
{
    [Fact]
    public void Add_Songs()
    {
        Playlist playlist = new();

        Song[] songs =
        [
            new Song() { FileName = "Song1.mp3" },
            new Song() { FileName = "Song2.mp3" },
            new Song() { FileName = "Song3.mp3" }
        ];

        playlist.AddSongs(songs);

        playlist.Songs.Count.ShouldBe(3);

        Song song = new() { FileName = "Song4.mp3" };
        playlist.AddSong(song);

        playlist.Songs.Count.ShouldBe(4);
        playlist.Songs[3].Song.FileName.ShouldBe("Song4.mp3");

        Song song2 = new() { FileName = "Song5.mp3" };
        playlist.AddSong(song2, 1);

        playlist.Songs.Count.ShouldBe(5);
        playlist.Songs[1].Song.FileName.ShouldBe("Song5.mp3");
    }

    [Fact]
    public void Sort_Songs()
    {
        Playlist playlist = new();

        Song[] songs =
        [
            new Song() { FileName = "Song1.mp3", Album = "Album 2", TrackNumber = 2 },
            new Song() { FileName = "Song2.mp3", Album = "Album 1", TrackNumber = 2 },
            new Song() { FileName = "Song3.mp3", Album = "Album 2", TrackNumber = 1 },
            new Song() { FileName = "Song4.mp3", Album = "Album 1", TrackNumber = 1 },
            new Song() { FileName = "Song5.mp3", Album = "Album 2", TrackNumber = 3 },
        ];

        playlist.AddSongs(songs);

        SortOption[] sortOptions =
        [
            new("Album", ListSortDirection.Ascending),
            new("TrackNumber", ListSortDirection.Ascending)
        ];

        playlist.SortSongs([.. playlist.Songs], sortOptions);

        string[] expectedSortedFileNames =
        [
            "Song4.mp3",
            "Song2.mp3",
            "Song3.mp3",
            "Song1.mp3",
            "Song5.mp3"
        ];

        playlist.Songs.Select(x => x.Song.FileName).ToArray()
            .ShouldBeEquivalentTo(expectedSortedFileNames);
    }

    [Fact]
    public void Remove_Songs()
    {
        Playlist playlist = new();

        Song[] songs =
        [
            new Song() { FileName = "Song1.mp3" },
            new Song() { FileName = "Song2.mp3" },
            new Song() { FileName = "Song3.mp3" }
        ];

        playlist.AddSongs(songs);

        playlist.RemoveSong(1);

        string[] expectedFileNames =
        [
            "Song1.mp3",
            "Song3.mp3"
        ];

        playlist.Songs.Select(x => x.Song.FileName).ToArray()
            .ShouldBeEquivalentTo(expectedFileNames);
    }

    [Fact]
    public void Lock_Playlist()
    {
        Playlist playlist = new();

        Song[] songs =
        [
            new Song() { FileName = "Song1.mp3" },
            new Song() { FileName = "Song2.mp3" },
            new Song() { FileName = "Song3.mp3" }
        ];

        playlist.AddSongs(songs);

        playlist.IsLocked = true;

        Song song = new() { FileName = "Song4.mp3" };
        playlist.AddSong(song);

        playlist.Songs.Count.ShouldBe(3);

        playlist.RemoveSong(0);

        playlist.Songs.Count.ShouldBe(3);
    }

    //public void Get_Playlists()
    //{
    //    //PlaylistRepository playlistRepository = new();
    //    //playlistRepository.Get().Returns()
    //}
}