// <copyright file="CopyToExtensionsTests.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

#pragma warning disable CA1707 // Identifiers should not contain underscores - xUnit test naming convention
#pragma warning disable CA1861 // Avoid constant arrays as arguments - required for xUnit theory test data

namespace Jellyfin.Extensions.Tests
{
    using System;
    using System.Collections.Generic;
    using Xunit;

    /// <summary>
    /// Tests for CopyTo extension methods.
    /// </summary>
    public static class CopyToExtensionsTests
    {
        /// <summary>
        /// Gets test data for valid CopyTo operations.
        /// </summary>
        /// <returns>The test data.</returns>
        public static TheoryData<IReadOnlyList<int>, IList<int>, int, IList<int>> CopyTo_Valid_Correct_TestData()
        {
            TheoryData<IReadOnlyList<int>, IList<int>, int, IList<int>> data = new TheoryData<IReadOnlyList<int>, IList<int>, int, IList<int>>
            {
                { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 0, new[] { 0, 1, 2, 3, 4, 5 } },
                { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 2, new[] { 5, 4, 0, 1, 2, 0 } },
            };

            return data;
        }

        /// <summary>
        /// Tests that CopyTo correctly copies elements.
        /// </summary>
        /// <param name="source">The source list.</param>
        /// <param name="destination">The destination list.</param>
        /// <param name="index">The starting index.</param>
        /// <param name="expected">The expected result.</param>
        [Theory]
        [MemberData(nameof(CopyTo_Valid_Correct_TestData))]
        public static void CopyTo_Valid_Correct(IReadOnlyList<int> source, IList<int> destination, int index, IList<int> expected)
        {
            source.CopyTo(destination, index);
            Assert.Equal(expected, destination);
        }

        /// <summary>
        /// Gets test data for invalid CopyTo operations that should throw.
        /// </summary>
        /// <returns>The test data.</returns>
        public static TheoryData<IReadOnlyList<int>, IList<int>, int> CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData()
        {
            TheoryData<IReadOnlyList<int>, IList<int>, int> data = new TheoryData<IReadOnlyList<int>, IList<int>, int>
            {
                { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, -1 },
                { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 6 },
                { new[] { 0, 1, 2 }, Array.Empty<int>(), 0 },
                { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0 }, 0 },
                { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 1 },
            };

            return data;
        }

        /// <summary>
        /// Tests that CopyTo throws ArgumentOutOfRangeException for invalid inputs.
        /// </summary>
        /// <param name="source">The source list.</param>
        /// <param name="destination">The destination list.</param>
        /// <param name="index">The starting index.</param>
        [Theory]
        [MemberData(nameof(CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData))]
        public static void CopyTo_Invalid_ThrowsArgumentOutOfRangeException(IReadOnlyList<int> source, IList<int> destination, int index)
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => source.CopyTo(destination, index));
        }
    }
}

#pragma warning restore CA1707
#pragma warning restore CA1861
