using FluentAssertions;
using BookingService.Domain.AggregatesModel.AppointmentAggregate;
using BookingService.Domain.Exceptions;
using Xunit;

namespace BookingService.UnitTests.Domain;

/// <summary>
/// EN: Unit tests for appointment aggregate behavior.
/// VI: Unit tests cho hành vi aggregate cuộc hẹn.
/// </summary>
public class AppointmentAggregateTests
{
    [Fact]
    public void CreateAppointment_ShouldInitializeAsScheduled()
    {
        // Act
        var appointment = new Appointment(
            Guid.NewGuid(),
            Guid.NewGuid(),
            DateTime.UtcNow.AddHours(1),
            DateTime.UtcNow.AddHours(2),
            Guid.NewGuid());

        // Assert
        appointment.Status.Should().Be("Pending");
        appointment.Id.Should().NotBeEmpty();
    }

    [Fact]
    public void Complete_AfterConfirmAndStart_ShouldSetCompleted()
    {
        // Arrange
        var appointment = new Appointment(
            Guid.NewGuid(),
            Guid.NewGuid(),
            DateTime.UtcNow.AddHours(2),
            DateTime.UtcNow.AddHours(3));
        appointment.Confirm();
        appointment.MarkAsInProgress();

        // Act
        appointment.Complete();

        // Assert
        appointment.Status.Should().Be("Completed");
    }

    [Fact]
    public void Cancel_WhenCompleted_ShouldThrowDomainException()
    {
        // Arrange
        var appointment = new Appointment(
            Guid.NewGuid(),
            Guid.NewGuid(),
            DateTime.UtcNow.AddHours(2),
            DateTime.UtcNow.AddHours(3));
        appointment.Confirm();
        appointment.MarkAsInProgress();
        appointment.Complete();

        // Act
        var action = () => appointment.Cancel("Customer requested");

        // Assert
        action.Should().Throw<DomainException>();
    }
}
