CREATE TABLE seasonpitchingstats (
    -- Primary identifiers (composite primary key)
    player_id INTEGER NOT NULL,
    season INTEGER NOT NULL,

    -- Additional identifiers and metadata
    name VARCHAR(255) NOT NULL,
    sbaplayer_id INTEGER,
    team_id INTEGER NOT NULL,
    player_team_id INTEGER NOT NULL,
    player_team_abbrev VARCHAR(10) NOT NULL,

    -- Counting stats
    tbf INTEGER NOT NULL DEFAULT 0,
    outs INTEGER NOT NULL DEFAULT 0,
    games INTEGER NOT NULL DEFAULT 0,

    -- Decision Info  
    gs INTEGER NOT NULL DEFAULT 0,
    win INTEGER NOT NULL DEFAULT 0,
    loss INTEGER NOT NULL DEFAULT 0,
    hold INTEGER NOT NULL DEFAULT 0,
    saves INTEGER NOT NULL DEFAULT 0,
    bsave INTEGER NOT NULL DEFAULT 0,
    ir INTEGER NOT NULL DEFAULT 0,
    irs INTEGER NOT NULL DEFAULT 0,

    -- Counting stats part 2
    ab INTEGER NOT NULL DEFAULT 0,
    run INTEGER NOT NULL DEFAULT 0,
    e_run INTEGER NOT NULL DEFAULT 0,
    hits INTEGER NOT NULL DEFAULT 0,
    double INTEGER NOT NULL DEFAULT 0,
    triple INTEGER NOT NULL DEFAULT 0,
    homerun INTEGER NOT NULL DEFAULT 0,
    bb INTEGER NOT NULL DEFAULT 0,
    so INTEGER NOT NULL DEFAULT 0,
    hbp INTEGER NOT NULL DEFAULT 0,
    sac INTEGER NOT NULL DEFAULT 0,
    ibb INTEGER NOT NULL DEFAULT 0,
    gidp INTEGER NOT NULL DEFAULT 0,
    sb INTEGER NOT NULL DEFAULT 0,
    cs INTEGER NOT NULL DEFAULT 0,
    bphr INTEGER NOT NULL DEFAULT 0,
    bpfo INTEGER NOT NULL DEFAULT 0,
    bp1b INTEGER NOT NULL DEFAULT 0,
    bplo INTEGER NOT NULL DEFAULT 0,
    wp INTEGER NOT NULL DEFAULT 0,
    balk INTEGER NOT NULL DEFAULT 0,

    -- Calculated stats
    wpa REAL NOT NULL DEFAULT 0.000,
    era REAL NOT NULL DEFAULT 0.00,
    whip REAL NOT NULL DEFAULT 0.00,
    avg REAL NOT NULL DEFAULT 0.000,
    obp REAL NOT NULL DEFAULT 0.000,
    slg REAL NOT NULL DEFAULT 0.000,
    ops REAL NOT NULL DEFAULT 0.000,
    woba REAL NOT NULL DEFAULT 0.000,
    hper9 REAL NOT NULL DEFAULT 0.0,
    kper9 REAL NOT NULL DEFAULT 0.0,
    bbper9 REAL NOT NULL DEFAULT 0.0,
    kperbb REAL NOT NULL DEFAULT 0.0,
    lob_2outs REAL NOT NULL DEFAULT 0.000,
    rbipercent REAL NOT NULL DEFAULT 0.000,
    re24 REAL NOT NULL DEFAULT 0.000,

    -- Constraints
    PRIMARY KEY (player_id, season),
    FOREIGN KEY (player_id) REFERENCES player (id),
    FOREIGN KEY (sbaplayer_id) REFERENCES sbaplayer (id),
    FOREIGN KEY (team_id) REFERENCES team (id)
);

-- Create indexes for better query performance
CREATE INDEX idx_seasonpitchingstats_season ON seasonpitchingstats (season);
CREATE INDEX idx_seasonpitchingstats_teamseason ON seasonpitchingstats (season, team_id);
CREATE INDEX idx_seasonpitchingstats_sbaplayer ON seasonpitchingstats (sbaplayer_id);