using Monitoring.Core.Domain.EventManagement;
using Monitoring.Features.AlarmManagement;

namespace Monitoring.Api.Tests;

public class AlarmScopeTransitionMatrixTest
{
	private readonly AlarmScopeTransitionMatrix _alarmScopeTransitionMatrix = new();

	[Theory]
	[InlineData(AlarmScopeStatus.New, true, true, null, AlarmScopeStatus.Accepted)]
	[InlineData(AlarmScopeStatus.New, false, true, null, AlarmScopeStatus.CamerasViewed)]
	[InlineData(AlarmScopeStatus.New, true, false, null, AlarmScopeStatus.Accepted)]
	[InlineData(AlarmScopeStatus.New, false, false, null, AlarmScopeStatus.CallsCompleted)]
	[InlineData(AlarmScopeStatus.Accepted, true, true, null, AlarmScopeStatus.CamerasViewed)]
	[InlineData(AlarmScopeStatus.Accepted, true, false, null, AlarmScopeStatus.CallsCompleted)]
	[InlineData(AlarmScopeStatus.CamerasViewed, true, true, null, AlarmScopeStatus.CallsCompleted)]
	[InlineData(AlarmScopeStatus.CamerasViewed, false, true, null, AlarmScopeStatus.CallsCompleted)]
	[InlineData(AlarmScopeStatus.CallsCompleted, true, true, false, AlarmScopeStatus.FalseAlarm)]
	[InlineData(AlarmScopeStatus.CallsCompleted, false, true, false, AlarmScopeStatus.FalseAlarm)]
	[InlineData(AlarmScopeStatus.CallsCompleted, true, false, false, AlarmScopeStatus.FalseAlarm)]
	[InlineData(AlarmScopeStatus.CallsCompleted, false, false, false, AlarmScopeStatus.FalseAlarm)]
	[InlineData(AlarmScopeStatus.CallsCompleted, true, true, true, AlarmScopeStatus.RealAlarm)]
	[InlineData(AlarmScopeStatus.CallsCompleted, false, true, true, AlarmScopeStatus.RealAlarm)]
	[InlineData(AlarmScopeStatus.CallsCompleted, true, false, true, AlarmScopeStatus.RealAlarm)]
	[InlineData(AlarmScopeStatus.CallsCompleted, false, false, true, AlarmScopeStatus.RealAlarm)]
	[InlineData(AlarmScopeStatus.FalseAlarm, true, true, null, AlarmScopeStatus.Resolved)]
	[InlineData(AlarmScopeStatus.FalseAlarm, false, true, null, AlarmScopeStatus.Resolved)]
	[InlineData(AlarmScopeStatus.FalseAlarm, true, false, null, AlarmScopeStatus.Resolved)]
	[InlineData(AlarmScopeStatus.FalseAlarm, false, false, null, AlarmScopeStatus.Resolved)]
	[InlineData(AlarmScopeStatus.RealAlarm, true, true, null, AlarmScopeStatus.Resolved)]
	[InlineData(AlarmScopeStatus.RealAlarm, false, true, null, AlarmScopeStatus.Resolved)]
	[InlineData(AlarmScopeStatus.RealAlarm, true, false, null, AlarmScopeStatus.Resolved)]
	[InlineData(AlarmScopeStatus.RealAlarm, false, false, null, AlarmScopeStatus.Resolved)]
	public void Success(
		AlarmScopeStatus status,
		bool hasCameras,
		bool hasResponsiblePersons,
		bool? isReal,
		AlarmScopeStatus expectedStatus
	)
	{
		var result = _alarmScopeTransitionMatrix.GetTransitionMatrix(
			status,
			hasCameras,
			hasResponsiblePersons,
			isReal
		);

		Assert.True(result.IsSuccess);
		Assert.Equal(expectedStatus, result.Value);
	}

	[Theory]
	[InlineData(AlarmScopeStatus.Resolved, true, true, null)]
	[InlineData(AlarmScopeStatus.Resolved, true, false, null)]
	[InlineData(AlarmScopeStatus.Resolved, false, true, null)]
	[InlineData(AlarmScopeStatus.Resolved, false, false, null)]
	[InlineData(AlarmScopeStatus.CallsCompleted, true, true, null)]
	[InlineData(AlarmScopeStatus.CallsCompleted, true, false, null)]
	[InlineData(AlarmScopeStatus.CallsCompleted, false, true, null)]
	[InlineData(AlarmScopeStatus.CallsCompleted, false, false, null)]
	public void Exception(
		AlarmScopeStatus status,
		bool hasCameras,
		bool hasResponsiblePersons,
		bool? isReal
	)
	{
		var result = _alarmScopeTransitionMatrix.GetTransitionMatrix(
			status,
			hasCameras,
			hasResponsiblePersons,
			isReal
		);

		Assert.True(result.IsFailure);
	}
}
