class User < ApplicationRecord

  has_many :recipes, dependent: :nullify
  has_many :foods, dependent: :nullify
  has_many :task_lists, dependent: :destroy

  has_secure_password

  validates :username, presence: true, uniqueness: { case_sensitive: false }

  def self.authenticate(username, password)
    find_by(username: username)&.authenticate(password)
  end

  def display_name
    self.full_name.present? ? self.full_name : self.username
  end

end
