# Path: socceraction/spadl/schema.py
# class SPADLSchema(pa.SchemaModel):
#     """Definition of a SPADL dataframe."""
# 
#     game_id: Series[Any] = pa.Field()
#     original_event_id: Series[Any] = pa.Field(nullable=True)
#     action_id: Series[int] = pa.Field()
#     period_id: Series[int] = pa.Field(ge=1, le=5)
#     time_seconds: Series[float] = pa.Field(ge=0)
#     team_id: Series[Any] = pa.Field()
#     player_id: Series[Any] = pa.Field()
#     start_x: Series[float] = pa.Field(ge=0, le=spadlconfig.field_length)
#     start_y: Series[float] = pa.Field(ge=0, le=spadlconfig.field_width)
#     end_x: Series[float] = pa.Field(ge=0, le=spadlconfig.field_length)
#     end_y: Series[float] = pa.Field(ge=0, le=spadlconfig.field_width)
#     bodypart_id: Series[int] = pa.Field(isin=spadlconfig.bodyparts_df().bodypart_id)
#     bodypart_name: Optional[Series[str]] = pa.Field(isin=spadlconfig.bodyparts_df().bodypart_name)
#     type_id: Series[int] = pa.Field(isin=spadlconfig.actiontypes_df().type_id)
#     type_name: Optional[Series[str]] = pa.Field(isin=spadlconfig.actiontypes_df().type_name)
#     result_id: Series[int] = pa.Field(isin=spadlconfig.results_df().result_id)
#     result_name: Optional[Series[str]] = pa.Field(isin=spadlconfig.results_df().result_name)
# 
#     class Config:  # noqa: D106
#         strict = True
#         coerce = True


import pandas as pd  # type: ignore
from pandera.typing import DataFrame, Series
from socceraction.spadl.schema import SPADLSchema
    Parameters
    ----------
    actions : pd.DataFrame
        SPADL action.
    scores : pd.Series
        The probability of scoring from each corresponding game state.
    concedes : pd.Series
        The probability of conceding from each corresponding game state.

    Returns
    -------
    pd.Series
        The defensive value of each action.
    """
    sameteam = _prev(actions.team_id) == actions.team_id
    prev_concedes = _prev(concedes) * sameteam + _prev(scores) * (~sameteam)

    toolong_idx = abs(actions.time_seconds - _prev(actions.time_seconds)) > _samephase_nb
    prev_concedes[toolong_idx] = 0

    # if the previous action was a goal, the odds of conceding are now 0
    prevgoal_idx = (_prev(actions.type_name).isin(['shot', 'shot_freekick', 'shot_penalty'])) & (
        _prev(actions.result_name) == 'success'
    )
    prev_concedes[prevgoal_idx] = 0

    return -(concedes - prev_concedes)


def value(

# Path: socceraction/spadl/schema.py
# class SPADLSchema(pa.SchemaModel):
#     """Definition of a SPADL dataframe."""
# 
#     game_id: Series[Any] = pa.Field()
#     original_event_id: Series[Any] = pa.Field(nullable=True)
#     action_id: Series[int] = pa.Field()
#     period_id: Series[int] = pa.Field(ge=1, le=5)
#     time_seconds: Series[float] = pa.Field(ge=0)
#     team_id: Series[Any] = pa.Field()
#     player_id: Series[Any] = pa.Field()
#     start_x: Series[float] = pa.Field(ge=0, le=spadlconfig.field_length)
#     start_y: Series[float] = pa.Field(ge=0, le=spadlconfig.field_width)
#     end_x: Series[float] = pa.Field(ge=0, le=spadlconfig.field_length)
#     end_y: Series[float] = pa.Field(ge=0, le=spadlconfig.field_width)
#     bodypart_id: Series[int] = pa.Field(isin=spadlconfig.bodyparts_df().bodypart_id)
#     bodypart_name: Optional[Series[str]] = pa.Field(isin=spadlconfig.bodyparts_df().bodypart_name)
#     type_id: Series[int] = pa.Field(isin=spadlconfig.actiontypes_df().type_id)
#     type_name: Optional[Series[str]] = pa.Field(isin=spadlconfig.actiontypes_df().type_name)
#     result_id: Series[int] = pa.Field(isin=spadlconfig.results_df().result_id)
#     result_name: Optional[Series[str]] = pa.Field(isin=spadlconfig.results_df().result_name)
# 
#     class Config:  # noqa: D106
#         strict = True
#         coerce = True


# Path: socceraction/vaep/formula.py
import pandas as pd  # type: ignore
from pandera.typing import DataFrame, Series
from socceraction.spadl.schema import SPADLSchema

    Parameters
    ----------
    actions : pd.DataFrame
        SPADL action.
    scores : pd.Series
        The probability of scoring from each corresponding game state.
    concedes : pd.Series
        The probability of conceding from each corresponding game state.

    Returns
    -------
    pd.Series
        The defensive value of each action.
    """
    sameteam = _prev(actions.team_id) == actions.team_id
    prev_concedes = _prev(concedes) * sameteam + _prev(scores) * (~sameteam)

    toolong_idx = abs(actions.time_seconds - _prev(actions.time_seconds)) > _samephase_nb
    prev_concedes[toolong_idx] = 0

    # if the previous action was a goal, the odds of conceding are now 0
    prevgoal_idx = (_prev(actions.type_name).isin(['shot', 'shot_freekick', 'shot_penalty'])) & (
        _prev(actions.result_name) == 'success'
    )
    prev_concedes[prevgoal_idx] = 0

    return -(concedes - prev_concedes)


def value(

    actions: DataFrame[SPADLSchema], Pscores: Series[float], Pconcedes: Series[float]