using JobTrackerApi.Services;
using Xunit;

namespace JobTrackerApi.Tests;

public sealed class EmailStatusClassifierTests
{
    [Fact]
    public void Detects_rejection()
    {
        var s = EmailStatusClassifier.Classify("Your application", "Thank you for your time. Unfortunately, we have decided not to proceed with your application.");
        Assert.NotNull(s);
        Assert.Equal("Rejected", s!.SuggestedStatus);
    }

    [Fact]
    public void Detects_offer()
    {
        var s = EmailStatusClassifier.Classify("Great news", "We are pleased to offer you the position of Backend Engineer.");
        Assert.NotNull(s);
        Assert.Equal("Offer", s!.SuggestedStatus);
    }

    [Fact]
    public void Detects_interview_invite()
    {
        var s = EmailStatusClassifier.Classify("Next steps", "We would like to invite you to interview next week. What is your availability for a call?");
        Assert.NotNull(s);
        Assert.Equal("Interview", s!.SuggestedStatus);
    }

    [Fact]
    public void Rejection_wins_over_interview_mention()
    {
        // A rejection email that references the interview the candidate had must classify as Rejected.
        var s = EmailStatusClassifier.Classify(
            "Update on your application",
            "Thank you for taking the time to interview with us. Unfortunately, we will not be moving forward.");
        Assert.NotNull(s);
        Assert.Equal("Rejected", s!.SuggestedStatus);
    }

    [Fact]
    public void Weak_interview_cue_is_low_confidence()
    {
        var s = EmailStatusClassifier.Classify("Coding challenge", "Please complete this take-home assessment.");
        Assert.NotNull(s);
        Assert.Equal("Interview", s!.SuggestedStatus);
        Assert.Equal("low", s.Confidence);
    }

    [Fact]
    public void Returns_null_for_neutral_email()
    {
        Assert.Null(EmailStatusClassifier.Classify("Re: question", "Thanks for the info, that answers my question about the parking."));
    }

    [Fact]
    public void Handles_empty_input()
        => Assert.Null(EmailStatusClassifier.Classify(null, null));
}
