###############################################################################
# Datatype to represent an item belonging to a season. A collection of
#  EpisodeItems.
###############################################################################
class Episode < ActiveRecord::Base
  include SoftDelete
  
  belongs_to :season
  has_many  :episode_items, inverse_of: :episode, dependent: :destroy

  scope :published, ->{ where({deleted_at: nil}) }
  scope :deleted,   ->{ where.not(deleted_at: nil) }

  validates :season_id, presence: true, numericality: { only_integer: true }
  validates :description, format: { without: DontGoToWork::EMPTY_SPACE_PATTERN }
  validates :order, presence: true, numericality: { only_integer: true, greater_than: -1 }
  validates :title, presence: true, uniqueness: true, length: { in: 3..64 }, format: {
    with: DontGoToWork::TITLE_PATTERN
  }
  validates :short_description, presence: true, length: {in: 3..256}, format: {
    without: DontGoToWork::EMPTY_SPACE_PATTERN
  }
end
