using MetagraphOptimization
using QEDbase

import MetagraphOptimization.caninteract
import MetagraphOptimization.issame
import MetagraphOptimization.interaction_result
import MetagraphOptimization.propagation_result
import MetagraphOptimization.direction

def_momentum = SFourMomentum(1.0, 0.0, 0.0, 0.0)

testparticleTypes = [
    PhotonStateful{Incoming},
    PhotonStateful{Outgoing},
    FermionStateful{Incoming},
    FermionStateful{Outgoing},
    AntiFermionStateful{Incoming},
    AntiFermionStateful{Outgoing},
]

testparticleTypesPropagated = [
    PhotonStateful{Outgoing},
    PhotonStateful{Incoming},
    FermionStateful{Outgoing},
    FermionStateful{Incoming},
    AntiFermionStateful{Outgoing},
    AntiFermionStateful{Incoming},
]

@testset "Interaction Result" begin
    for p1 in testparticleTypes, p2 in testparticleTypes
        if !caninteract(p1, p2)
            @test_throws AssertionError interaction_result(p1, p2)
        else
            @test interaction_result(p1, p2) in setdiff(testparticleTypes, [p1, p2])
            @test issame(interaction_result(p1, p2), interaction_result(p2, p1))
        end
    end
end

@testset "Propagation Result" begin
    for (p, propResult) in zip(testparticleTypes, testparticleTypesPropagated)
        @test issame(propagation_result(p), propResult)
        @test direction(propagation_result(p)(def_momentum)) != direction(p(def_momentum))
    end
end
