using Meezi.API.Services;
using Meezi.Core.Discover;

namespace Meezi.API.Tests;

public class DiscoverFilterTests
{
    [Fact]
    public void Matches_WhenThemeOverlaps()
    {
        var profile = new CafeDiscoverProfile { Themes = ["modern", "cozy"] };
        var filters = new DiscoverFilterParams(Themes: ["modern"]);
        Assert.True(DiscoverProfileMatcher.Matches(profile, filters));
    }

    [Fact]
    public void Rejects_WhenThemeMissing()
    {
        var profile = new CafeDiscoverProfile { Themes = ["vintage"] };
        var filters = new DiscoverFilterParams(Themes: ["modern"]);
        Assert.False(DiscoverProfileMatcher.Matches(profile, filters));
    }

    [Fact]
    public void RequireProfile_RejectsEmptyProfile()
    {
        var profile = new CafeDiscoverProfile();
        var filters = new DiscoverFilterParams(RequireProfile: true);
        Assert.False(DiscoverProfileMatcher.Matches(profile, filters));
    }

    [Fact]
    public void FromQuery_ParsesCommaSeparated()
    {
        var f = DiscoverFilterParams.FromQuery(
            city: "تهران",
            q: null,
            minRating: 4,
            sort: "rating",
            themes: "modern, cozy",
            vibes: "romantic",
            occasions: null,
            spaceFeatures: "outdoor",
            noise: "quiet",
            priceTier: "mid",
            size: null,
            requireProfile: true);
        Assert.Equal("تهران", f.City);
        Assert.Equal(4, f.MinRating);
        Assert.Contains("modern", f.Themes!);
        Assert.Contains("cozy", f.Themes!);
        Assert.Equal("quiet", f.NoiseLevel);
    }
}
