# 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
import socceraction.atomic.spadl.config as atomicspadl
from pandera.typing import DataFrame
from socceraction.atomic.spadl import AtomicSPADLSchema


    Returns
    -------
    pd.DataFrame
        A dataframe with a column 'concedes' and a row for each action set to
        True if a goal was conceded by the team possessing the ball within the
        next x actions; otherwise False.
    """
    # merging goals, owngoals and team_ids
    goals = actions['type_id'] == atomicspadl.actiontypes.index('goal')
    owngoals = actions['type_id'] == atomicspadl.actiontypes.index('owngoal')
    y = pd.concat([goals, owngoals, actions['team_id']], axis=1)
    y.columns = ['goal', 'owngoal', 'team_id']

    # adding future results
    for i in range(1, nr_actions):
        for c in ['team_id', 'goal', 'owngoal']:
            shifted = y[c].shift(-i)
            shifted[-i:] = y[c][len(y) - 1]
            y['%s+%d' % (c, i)] = shifted

    res = y['owngoal']
    for i in range(1, nr_actions):
        gi = y['goal+%d' % i] & (y['team_id+%d' % i] != y['team_id'])
        ogi = y['owngoal+%d' % i] & (y['team_id+%d' % i] == y['team_id'])
        res = res | gi | ogi

    return pd.DataFrame(res, columns=['concedes'])



# 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/labels.py
import pandas as pd
import socceraction.atomic.spadl.config as atomicspadl
from pandera.typing import DataFrame
from socceraction.atomic.spadl import AtomicSPADLSchema


    Returns
    -------
    pd.DataFrame
        A dataframe with a column 'concedes' and a row for each action set to
        True if a goal was conceded by the team possessing the ball within the
        next x actions; otherwise False.
    """
    # merging goals, owngoals and team_ids
    goals = actions['type_id'] == atomicspadl.actiontypes.index('goal')
    owngoals = actions['type_id'] == atomicspadl.actiontypes.index('owngoal')
    y = pd.concat([goals, owngoals, actions['team_id']], axis=1)
    y.columns = ['goal', 'owngoal', 'team_id']

    # adding future results
    for i in range(1, nr_actions):
        for c in ['team_id', 'goal', 'owngoal']:
            shifted = y[c].shift(-i)
            shifted[-i:] = y[c][len(y) - 1]
            y['%s+%d' % (c, i)] = shifted

    res = y['owngoal']
    for i in range(1, nr_actions):
        gi = y['goal+%d' % i] & (y['team_id+%d' % i] != y['team_id'])
        ogi = y['owngoal+%d' % i] & (y['team_id+%d' % i] == y['team_id'])
        res = res | gi | ogi

    return pd.DataFrame(res, columns=['concedes'])



def goal_from_shot(actions: DataFrame[AtomicSPADLSchema]) -> pd.DataFrame:
