# Path: socceraction/atomic/spadl/schema.py
# class AtomicSPADLSchema(pa.SchemaModel):
#     """Definition of an Atomic-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()
#     x: Series[float] = pa.Field(ge=0, le=spadlconfig.field_length)
#     y: Series[float] = pa.Field(ge=0, le=spadlconfig.field_width)
#     dx: Series[float] = pa.Field(ge=-spadlconfig.field_length, le=spadlconfig.field_length)
#     dy: Series[float] = pa.Field(ge=-spadlconfig.field_width, 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)
# 
#     class Config:  # noqa: D106
#         strict = True
#         coerce = True


import pandas as pd
from pandera.typing import DataFrame, Series
from socceraction.atomic.spadl import AtomicSPADLSchema

    ----------
    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
        he ffensive value of each action.
    """
    sameteam = _prev(actions.team_id) == actions.team_id
    prev_scores = _prev(scores) * sameteam + _prev(concedes) * (~sameteam)

    # if the previous action was too long ago, the odds of scoring are now 0
    # toolong_idx = (
    #    abs(actions.time_seconds - _prev(actions.time_seconds)) > _samephase_nb
    # )
    # prev_scores[toolong_idx] = 0

    # if the previous action was a goal, the odds of scoring are now 0
    prevgoal_idx = _prev(actions.type_name).isin(['goal', 'owngoal'])
    prev_scores[prevgoal_idx] = 0

    return scores - prev_scores


def defensive_value(

# Path: socceraction/atomic/spadl/schema.py
# class AtomicSPADLSchema(pa.SchemaModel):
#     """Definition of an Atomic-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()
#     x: Series[float] = pa.Field(ge=0, le=spadlconfig.field_length)
#     y: Series[float] = pa.Field(ge=0, le=spadlconfig.field_width)
#     dx: Series[float] = pa.Field(ge=-spadlconfig.field_length, le=spadlconfig.field_length)
#     dy: Series[float] = pa.Field(ge=-spadlconfig.field_width, 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)
# 
#     class Config:  # noqa: D106
#         strict = True
#         coerce = True


# Path: socceraction/atomic/vaep/formula.py
import pandas as pd
from pandera.typing import DataFrame, Series
from socceraction.atomic.spadl import AtomicSPADLSchema

    ----------
    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
        he ffensive value of each action.
    """
    sameteam = _prev(actions.team_id) == actions.team_id
    prev_scores = _prev(scores) * sameteam + _prev(concedes) * (~sameteam)

    # if the previous action was too long ago, the odds of scoring are now 0
    # toolong_idx = (
    #    abs(actions.time_seconds - _prev(actions.time_seconds)) > _samephase_nb
    # )
    # prev_scores[toolong_idx] = 0

    # if the previous action was a goal, the odds of scoring are now 0
    prevgoal_idx = _prev(actions.type_name).isin(['goal', 'owngoal'])
    prev_scores[prevgoal_idx] = 0

    return scores - prev_scores


def defensive_value(

    actions: DataFrame[AtomicSPADLSchema], scores: Series[float], concedes: Series[float]
