/**
 *  Matchup class:
 *  The Matchup class holds two ParticipantInfo objects representing a
 *  match between two participants.
 *
 *  @author Alyce Brady
 *  Creation Date: Fall 2025
 */


public class Matchup
{
    private ParticipantInfo participant1;
    private ParticipantInfo participant2;

    /** Constructs a Matchup instance with two participants.
     *      @param participant1  information about a participant
     *      @param participant2  information about a second participant
     */
    public Matchup (ParticipantInfo participant1, ParticipantInfo participant2)
    {
        this.participant1 = participant1;
        this.participant2 = participant2;
    }

    /** Returns the first participant's info.
     *      @return the first participant's info
     */
    public ParticipantInfo getParticipant1()
    {
        return this.participant1;
    }

    /** Returns the second participant's info.
     *      @return the second participant's info
     */
    public ParticipantInfo getParticipant2()
    {
        return this.participant2;
    }

    /** Returns the participant with the higher score, or returns
     *  participant1 if the scores are tied.
     *      @return the participant with the higher score.
     */
    public ParticipantInfo getWinner()
    {
        int comparison =
            participant1.getScore().compareTo(participant2.getScore());
        return (comparison >= 0 ? participant1 : participant2);
    }

    /** Returns the participant with the lower score, or returns
     *  participant2 if the scores are tied.
     *      @return the participant with the lower score.
     */
    public ParticipantInfo getLoser()
    {
        int comparison =
            participant1.getScore().compareTo(participant2.getScore());
        return (comparison >= 0 ? participant2 : participant1);
    }

    /** Creates a string reporting participants without scores.
     *    @return string reporting participants without scores
     */
    public String noScores()
    {
        return participant1.rankThenName() + " vs. " +
               participant2.rankThenName();
    }

    /** {@inheritDoc}
     */
    @Override
    public String toString()
    {
        return participant1.nameThenScore() + " vs. " +
               participant2.nameThenScore();
    }

}
