# frozen_string_literal: true

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
FactoryBot.define do
  factory :user do
    username            { FFaker::InternetSE.user_name_variant_short }
    email               { FFaker::Internet.email }
    first_name          { FFaker::Name.first_name }
    last_name           { FFaker::Name.last_name }
    title               { FactoryBot.generate(:title) }
    company             { FFaker::Company.name }
    alt_email           { FFaker::Internet.email }
    phone               { FFaker::PhoneNumber.phone_number }
    mobile              { FFaker::PhoneNumber.phone_number }
    aim                 { nil }
    yahoo               { nil }
    google              { nil }
    admin               { false }
    encrypted_password  { SecureRandom.hex(64) }
    password_salt       { SecureRandom.hex(64) }
    last_sign_in_at     { FactoryBot.generate(:time) }
    current_sign_in_at  { FactoryBot.generate(:time) }
    last_sign_in_ip     { "127.0.0.1" }
    current_sign_in_ip  { "127.0.0.1" }
    sign_in_count       { rand(1..100) }
    deleted_at          { nil }
    updated_at          { FactoryBot.generate(:time) }
    created_at          { FactoryBot.generate(:time) }
    confirmed_at        { Time.now.utc }
    suspended_at        { nil }
    password            { "password" }
    password_confirmation { "password" }

    # For unit tests, we dont need to enforce uniqueness
    to_create { |instance| instance.save(validate: false) }
  end

  factory :admin do
    admin { true }
  end

  factory :permission do
    user
    asset               { raise "Please specify :asset for the permission" }
    updated_at          { FactoryBot.generate(:time) }
    created_at          { FactoryBot.generate(:time) }
  end

  factory :preference do
    user
    name                { raise "Please specify :name for the preference" }
    value               { raise "Please specify :value for the preference" }
    updated_at          { FactoryBot.generate(:time) }
    created_at          { FactoryBot.generate(:time) }
  end

  factory :group do
    name                { FFaker::Company.name }
    updated_at          { FactoryBot.generate(:time) }
    created_at          { FactoryBot.generate(:time) }
  end
end
