using JSMR.Infrastructure.Scanning;
using Shouldly;

namespace JSMR.Tests.Unit;

public class DLSiteSearchFilterBuilderTests
{
    [Fact]
    public void Build_Simple_Query()
    {
        var filterBuilder = new DLSiteSearchFilterBuilder()
            .UseDefaultLocale()
            .IncludeJapaneseSupportedLanguage();

        string url = filterBuilder.BuildSearchQuery(1, 100);

        using var writer = new StringWriter();

        writer.Write($"https://www.dlsite.com/maniax/");
        writer.Write($"fsr/=/language/jp/");
        writer.Write("sex_category[0]/male/");
        writer.Write("ana_flg/all/");
        writer.Write("work_category[0]/doujin/");
        writer.Write("order[0]/release_d/");
        writer.Write("work_type_category[0]/audio/");
        writer.Write("work_type_category_name[0]/ボイス・ASMR/");

        writer.Write("options_and_or/and/");
        writer.Write($"options[0]/JPN/");

        writer.Write($"per_page/100/");
        writer.Write($"page/1/");
        writer.Write("show_type/1/");
        writer.Write($"?locale=ja_JP");

        url.ShouldBe(writer.ToString());
    }

    [Fact]
    public void Build_Advanced_Query()
    {
        var filterBuilder = new DLSiteSearchFilterBuilder()
            .UseEnglishLocale()
            .IncludeJapaneseSupportedLanguage()
            .IncludeEnglishSupportedLanguage()
            .ExcludeMakers(["RG0000001", "RG0000002", "", "RG0000001"])
            .ExcludePartiallyAIGeneratedWorks()
            .ExcludeAIGeneratedWorks();

        string url = filterBuilder.BuildSearchQuery(1, 100);

        using var writer = new StringWriter();

        writer.Write($"https://www.dlsite.com/maniax/");
        writer.Write($"fsr/=/language/en/");
        writer.Write("sex_category[0]/male/");
        writer.Write("ana_flg/all/");
        writer.Write("work_category[0]/doujin/");
        writer.Write("order[0]/release_d/");
        writer.Write("work_type_category[0]/audio/");
        writer.Write("work_type_category_name[0]/ボイス・ASMR/");

        writer.Write("options_and_or/and/");
        writer.Write($"options[0]/JPN/");
        writer.Write($"options[1]/ENG/");

        writer.Write($"keyword_maker_name/-RG0000001+-RG0000002/");

        writer.Write($"options_not[0]/AIP/");
        writer.Write($"options_not[1]/AIG/");

        writer.Write($"per_page/100/");
        writer.Write($"page/1/");
        writer.Write("show_type/1/");
        writer.Write($"?locale=en_US");

        url.ShouldBe(writer.ToString());
    }
}