class ProcedurePath < ApplicationRecord
  validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, presence: true, allow_blank: false, allow_nil: false
  validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false
  validates :procedure_id, presence: true, allow_blank: false, allow_nil: false

  belongs_to :procedure
  belongs_to :administrateur

  def hide!
    destroy!
  end

  def publish!(new_procedure)
    if procedure&.publiee?
      procedure.archive!
    end
    update!(procedure: new_procedure)
  end
end
