"""
This program has been developed by students from the bachelor Computer Science at Utrecht
University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
"""

import pytest
from pydantic import ValidationError

from control_backend.schemas.ri_message import GestureCommand, RIEndpoint, RIMessage, SpeechCommand


def valid_command_1():
    return SpeechCommand(data="Hallo?")


def valid_command_2():
    return GestureCommand(endpoint=RIEndpoint.GESTURE_TAG, data="happy")


def valid_command_3():
    return GestureCommand(endpoint=RIEndpoint.GESTURE_SINGLE, data="happy_1")


def invalid_command_1():
    return RIMessage(endpoint=RIEndpoint.PING, data="Hello again.")


def invalid_command_2():
    return RIMessage(endpoint=RIEndpoint.PING, data="Hey!")


def invalid_command_3():
    return RIMessage(endpoint=RIEndpoint.GESTURE_SINGLE, data={1, 2, 3})


def invalid_command_4():
    test: RIMessage = GestureCommand(endpoint=RIEndpoint.GESTURE_SINGLE, data="asdsad")

    def change_endpoint(msg: RIMessage):
        msg.endpoint = RIEndpoint.PING

    change_endpoint(test)
    return test


def test_valid_speech_command_1():
    command = valid_command_1()
    RIMessage.model_validate(command)
    SpeechCommand.model_validate(command)


def test_valid_gesture_command_1():
    command = valid_command_2()
    RIMessage.model_validate(command)
    GestureCommand.model_validate(command)


def test_valid_gesture_command_2():
    command = valid_command_3()
    RIMessage.model_validate(command)
    GestureCommand.model_validate(command)


def test_invalid_speech_command_1():
    command = invalid_command_1()
    RIMessage.model_validate(command)

    with pytest.raises(ValidationError):
        SpeechCommand.model_validate(command)


def test_invalid_gesture_command_1():
    command = invalid_command_2()
    RIMessage.model_validate(command)

    with pytest.raises(ValidationError):
        GestureCommand.model_validate(command)


def test_invalid_gesture_command_2():
    command = invalid_command_3()
    RIMessage.model_validate(command)

    with pytest.raises(ValidationError):
        GestureCommand.model_validate(command)


def test_invalid_gesture_command_3():
    command = invalid_command_4()
    RIMessage.model_validate(command)

    with pytest.raises(ValidationError):
        GestureCommand.model_validate(command)
