# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2026_05_26_120000) do
  # These are extensions that must be enabled in order to support this database
  enable_extension "pgcrypto"
  enable_extension "plpgsql"

  create_table "device_states", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "stream_session_id", null: false
    t.string "device_role", null: false
    t.integer "battery_level"
    t.string "network_type"
    t.integer "signal_strength"
    t.integer "current_bitrate"
    t.integer "target_bitrate"
    t.integer "fps"
    t.datetime "last_seen_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["stream_session_id", "device_role"], name: "index_device_states_on_stream_session_id_and_device_role", unique: true
    t.index ["stream_session_id"], name: "index_device_states_on_stream_session_id"
  end

  create_table "matches", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "team_id", null: false
    t.string "opponent_name", null: false
    t.string "location"
    t.datetime "scheduled_at"
    t.string "sport", default: "volleyball"
    t.integer "sets_to_win", default: 3
    t.jsonb "roster_numbers", default: []
    t.string "category"
    t.string "phase"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.jsonb "scoring_rules", default: {}, null: false
    t.index ["team_id"], name: "index_matches_on_team_id"
  end

  create_table "plans", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.string "slug", null: false
    t.string "name", null: false
    t.string "stripe_price_id"
    t.jsonb "features", default: {}, null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["slug"], name: "index_plans_on_slug", unique: true
  end

  create_table "recordings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "stream_session_id", null: false
    t.uuid "team_id", null: false
    t.string "status", default: "processing", null: false
    t.string "storage_path"
    t.datetime "expires_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["expires_at"], name: "index_recordings_on_expires_at"
    t.index ["stream_session_id"], name: "index_recordings_on_stream_session_id", unique: true
    t.index ["team_id"], name: "index_recordings_on_team_id"
  end

  create_table "score_states", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "stream_session_id", null: false
    t.integer "home_sets", default: 0
    t.integer "away_sets", default: 0
    t.integer "home_points", default: 0
    t.integer "away_points", default: 0
    t.integer "current_set", default: 1
    t.string "period"
    t.boolean "timeout_home", default: false
    t.boolean "timeout_away", default: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.jsonb "set_partials", default: [], null: false
    t.index ["stream_session_id"], name: "index_score_states_on_stream_session_id", unique: true
  end

  create_table "stream_events", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "stream_session_id", null: false
    t.string "event_type", null: false
    t.jsonb "metadata", default: {}
    t.datetime "occurred_at", null: false
    t.index ["stream_session_id", "occurred_at"], name: "index_stream_events_on_stream_session_id_and_occurred_at"
    t.index ["stream_session_id"], name: "index_stream_events_on_stream_session_id"
  end

  create_table "stream_sessions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "match_id", null: false
    t.uuid "user_id", null: false
    t.string "status", default: "idle", null: false
    t.string "platform", default: "youtube"
    t.text "stream_key_encrypted"
    t.string "rtmp_url"
    t.string "youtube_broadcast_id"
    t.string "youtube_stream_id"
    t.string "privacy_status", default: "unlisted"
    t.string "quality_preset", default: "720p_30_2.5mbps"
    t.integer "target_bitrate", default: 2500000
    t.integer "target_fps", default: 30
    t.datetime "started_at"
    t.datetime "ended_at"
    t.integer "total_duration_secs", default: 0
    t.integer "disconnection_count", default: 0
    t.string "publish_token"
    t.string "pairing_token_digest"
    t.datetime "pairing_token_expires_at"
    t.string "timeout_job_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["match_id"], name: "index_stream_sessions_on_match_id"
    t.index ["publish_token"], name: "index_stream_sessions_on_publish_token", unique: true
    t.index ["status"], name: "index_stream_sessions_on_status"
    t.index ["user_id"], name: "index_stream_sessions_on_user_id"
  end

  create_table "subscriptions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "team_id", null: false
    t.uuid "plan_id", null: false
    t.string "status", default: "active", null: false
    t.string "stripe_customer_id"
    t.string "stripe_subscription_id"
    t.datetime "current_period_start"
    t.datetime "current_period_end"
    t.boolean "cancel_at_period_end", default: false, null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["plan_id"], name: "index_subscriptions_on_plan_id"
    t.index ["stripe_subscription_id"], name: "index_subscriptions_on_stripe_subscription_id", unique: true, where: "(stripe_subscription_id IS NOT NULL)"
    t.index ["team_id"], name: "index_subscriptions_on_team_id", unique: true
  end

  create_table "team_invitations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "team_id", null: false
    t.string "email", null: false
    t.string "token_digest", null: false
    t.string "role", default: "member", null: false
    t.datetime "expires_at", null: false
    t.datetime "accepted_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["team_id", "email"], name: "index_team_invitations_on_team_id_and_email"
    t.index ["team_id"], name: "index_team_invitations_on_team_id"
    t.index ["token_digest"], name: "index_team_invitations_on_token_digest", unique: true
  end

  create_table "teams", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.string "name", null: false
    t.string "sport", default: "volleyball"
    t.string "logo_url"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "user_teams", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "user_id", null: false
    t.uuid "team_id", null: false
    t.string "role", default: "member", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["team_id"], name: "index_user_teams_on_team_id"
    t.index ["user_id", "team_id"], name: "index_user_teams_on_user_id_and_team_id", unique: true
    t.index ["user_id"], name: "index_user_teams_on_user_id"
  end

  create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.string "email", null: false
    t.string "password_digest", null: false
    t.string "name", null: false
    t.string "role", default: "coach", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["email"], name: "index_users_on_email", unique: true
  end

  create_table "youtube_credentials", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
    t.uuid "team_id", null: false
    t.text "access_token_encrypted"
    t.text "refresh_token_encrypted"
    t.datetime "expires_at"
    t.string "channel_id"
    t.string "channel_title"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["team_id"], name: "index_youtube_credentials_on_team_id"
  end

  add_foreign_key "device_states", "stream_sessions"
  add_foreign_key "matches", "teams"
  add_foreign_key "recordings", "stream_sessions"
  add_foreign_key "recordings", "teams"
  add_foreign_key "score_states", "stream_sessions"
  add_foreign_key "stream_events", "stream_sessions"
  add_foreign_key "stream_sessions", "matches"
  add_foreign_key "stream_sessions", "users"
  add_foreign_key "subscriptions", "plans"
  add_foreign_key "subscriptions", "teams"
  add_foreign_key "team_invitations", "teams"
  add_foreign_key "user_teams", "teams"
  add_foreign_key "user_teams", "users"
  add_foreign_key "youtube_credentials", "teams"
end
