import pytest

from m3m_twin.mission import MissionParameters, VirtualField, plan_virtual_mission


def test_virtual_field_is_twelve_hectares():
    assert VirtualField().area_m2 == 120_000


def test_default_mission_geometry_and_count():
    result = plan_virtual_mission()
    assert result["scanLineCount"] == 12
    assert result["captureEventCount"] == 408
    assert result["expectedImageFileCount"] == 2040


def test_capture_cadence_respects_two_seconds():
    result = plan_virtual_mission()
    assert result["actualCaptureIntervalS"] >= 2.0


def test_overlap_targets_are_met():
    result = plan_virtual_mission()
    assert result["actualFrontOverlapPct"] >= 80
    assert result["actualSideOverlapPct"] >= 70


def test_mission_retains_conservative_planning_reserve():
    result = plan_virtual_mission()
    assert result["singleFlightPlanningGate"] is True
    assert result["planningReserveMinutes"] > 10


def test_route_points_and_events_stay_inside_virtual_field():
    result = plan_virtual_mission()
    for event in result["captureEvents"]:
        assert 0 < event["xM"] < 400
        assert 0 < event["yM"] < 300


def test_route_is_explicitly_non_operational():
    result = plan_virtual_mission()
    assert result["notForFlight"] is True
    assert result["flightExecutionAuthorized"] is False
    assert result["coordinateSystem"] == "LOCAL_SYNTHETIC_METRES"


def test_too_fast_capture_request_is_rejected():
    with pytest.raises(ValueError):
        plan_virtual_mission(parameters=MissionParameters(capture_interval_s=1.0))


def test_low_sun_angle_is_rejected():
    with pytest.raises(ValueError):
        plan_virtual_mission(parameters=MissionParameters(sun_altitude_deg=29.9))
