<commit_before># frozen_string_literal: true

class User < ApplicationRecord
  include User::Relationship
  include User::Relationship::Follow
  include User::Relationship::Block
  include User::AnswerMethods
  include User::BanMethods
  include User::InboxMethods
  include User::QuestionMethods
  include User::ReactionMethods
  include User::RelationshipMethods
  include User::TimelineMethods
  include ActiveModel::OneTimePassword

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :async, :registerable,
         :recoverable, :rememberable, :trackable,
         :validatable, :confirmable, :authentication_keys => [:login]

  has_one_time_password
  enum otp_module: { disabled: 0, enabled: 1 }, _prefix: true
  attr_accessor :otp_attempt, :otp_validation

  rolify

#   attr_accessor :login

  has_many :questions, dependent: :destroy_async
  has_many :answers, dependent: :destroy_async
  has_many :comments, dependent: :destroy_async
  has_many :inboxes, dependent: :destroy_async
  has_many :smiles, class_name: "Appendable::Reaction", dependent: :destroy_async
  has_many :services, dependent: :destroy_async
  has_many :notifications, foreign_key: :recipient_id, dependent: :destroy_async
  has_many :reports, dependent: :destroy_async
  has_many :moderation_comments, dependent: :destroy_async
  has_many :moderation_votes, dependent: :destroy_async
  has_many :lists, dependent: :destroy_async
  has_many :list_memberships, class_name: "ListMember", foreign_key: 'user_id', dependent: :destroy_async
  has_many :mute_rules, dependent: :destroy_async
  has_many :anonymous_blocks, dependent: :destroy_async

  has_many :subscriptions, dependent: :destroy_async
  has_many :totp_recovery_codes, dependent: :destroy_async

  has_one :profile, dependent: :destroy_async
  has_one :theme, dependent: :destroy_async

  has_many :bans, class_name: 'UserBan', dependent: :destroy_async
  has_many :banned_users, class_name: 'UserBan',
                          foreign_key: 'banned_by_id',
                          dependent: :nullify

  SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/
  WEBSITE_REGEX = /https?:\/\/([A-Za-z.\-]+)\/?(?:.*)/i

  before_validation do
    screen_name.strip!
  end

  validates :email, fake_email: true, typoed_email: true
  validates :screen_name, presence: true, format: { with: SCREEN_NAME_REGEX }, uniqueness: { case_sensitive: false }, screen_name: true

  mount_uploader :profile_picture, ProfilePictureUploader, mount_on: :profile_picture_file_name
  process_in_background :profile_picture
  mount_uploader :profile_header, ProfileHeaderUploader, mount_on: :profile_header_file_name
  process_in_background :profile_header

  # when a user has been deleted, all reports relating to the user become invalid<commit_msg>Correct lint errors<commit_after># frozen_string_literal: true

class User < ApplicationRecord
  include User::Relationship
  include User::Relationship::Follow
  include User::Relationship::Block
  include User::AnswerMethods
  include User::BanMethods
  include User::InboxMethods
  include User::QuestionMethods
  include User::ReactionMethods
  include User::RelationshipMethods
  include User::TimelineMethods
  include ActiveModel::OneTimePassword

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :async, :registerable,
         :recoverable, :rememberable, :trackable,
         :validatable, :confirmable, :authentication_keys => [:login]

  has_one_time_password
  enum otp_module: { disabled: 0, enabled: 1 }, _prefix: true
  attr_accessor :otp_attempt, :otp_validation

  rolify

#   attr_accessor :login

  has_many :questions, dependent: :destroy_async
  has_many :answers, dependent: :destroy_async
  has_many :comments, dependent: :destroy_async
  has_many :inboxes, dependent: :destroy_async
  has_many :smiles, class_name: "Appendable::Reaction", dependent: :destroy_async
  has_many :services, dependent: :destroy_async
  has_many :notifications, foreign_key: :recipient_id, dependent: :destroy_async
  has_many :reports, dependent: :destroy_async
  has_many :moderation_comments, dependent: :destroy_async
  has_many :moderation_votes, dependent: :destroy_async
  has_many :lists, dependent: :destroy_async
  has_many :list_memberships, class_name: "ListMember", dependent: :destroy_async
  has_many :mute_rules, dependent: :destroy_async
  has_many :anonymous_blocks, dependent: :destroy_async

  has_many :subscriptions, dependent: :destroy_async
  has_many :totp_recovery_codes, dependent: :destroy_async

  has_one :profile, dependent: :destroy_async
  has_one :theme, dependent: :destroy_async

  has_many :bans, class_name: "UserBan", dependent: :destroy_async
  has_many :banned_users, class_name: 'UserBan',
                          foreign_key: 'banned_by_id',
                          dependent: :nullify

  SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/
  WEBSITE_REGEX = /https?:\/\/([A-Za-z.\-]+)\/?(?:.*)/i

  before_validation do
    screen_name.strip!
  end

  validates :email, fake_email: true, typoed_email: true
  validates :screen_name, presence: true, format: { with: SCREEN_NAME_REGEX }, uniqueness: { case_sensitive: false }, screen_name: true

  mount_uploader :profile_picture, ProfilePictureUploader, mount_on: :profile_picture_file_name
  process_in_background :profile_picture
  mount_uploader :profile_header, ProfileHeaderUploader, mount_on: :profile_header_file_name
  process_in_background :profile_header

  # when a user has been deleted, all reports relating to the user become invalid
{'fraction_non_alphanumeric': 0.09145059565522075, 'fraction_numerical': 0.002452697967764541, 'mean_word_length': 5.509692132269099, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '871938', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1734, 'n_words': 427}