class TheatreSkipEventsController < ApplicationController
  def index
    limit = params[:limit].to_i
    limit = 50 if limit <= 0

    events =
        TheatreSkipEvent
        .where(theatre_id: params[:theatre_id])
        .includes(:post, tags: :tag_name)
        .order(created_at: :desc)
        .limit(limit)

    render json: events.map { |event|
      { id: event.id,
        theatre_id: event.theatre_id,
        post: { id: event.post.id, title: event.post.title, url: event.post.url },
        tags: event.tags.map { |tag| { id: tag.id, name: tag.name } },
        programme_position: event.programme_position,
        created_at: event.created_at }
    }
  end
end
