class ShopifyApp::Generators::UserModelGenerator

def create_expires_at_storage_in_user_model

def create_expires_at_storage_in_user_model
  expires_at_column_prompt = <<~PROMPT
    It is highly recommended that apps record the User session expiry date. \
    This will allow to check if the session has expired and re-authenticate \
    without a first call to Shopify.
    After running the migration, the `check_session_expiry_date` configuration can be enabled.
    The following migration will add an `expires_at` column to the User model. \
    Do you want to include this migration? [y/n]
  PROMPT
  if new_shopify_cli_app? || Rails.env.test? || yes?(expires_at_column_prompt)
    migration_template(
      "db/migrate/add_user_expires_at_column.erb",
      "db/migrate/add_user_expires_at_column.rb",
    )
  end
end

def create_scopes_storage_in_user_model

def create_scopes_storage_in_user_model
  scopes_column_prompt = <<~PROMPT
    It is highly recommended that apps record the access scopes granted by \
    merchants during app installation. See app/models/user.rb to modify how \
    access scopes are stored and retrieved.
    [WARNING] You will need to update the access_scopes accessors in the User model \
    to allow shopify_app to store and retrieve scopes when going through OAuth.
    The following migration will add an `access_scopes` column to the User model. \
    Do you want to include this migration? [y/n]
  PROMPT
  if new_shopify_cli_app? || Rails.env.test? || yes?(scopes_column_prompt)
    migration_template(
      "db/migrate/add_user_access_scopes_column.erb",
      "db/migrate/add_user_access_scopes_column.rb",
    )
  end
end

def create_user_fixtures

def create_user_fixtures
  copy_file("users.yml", "test/fixtures/users.yml")
end

def create_user_migration

def create_user_migration
  migration_template("db/migrate/create_users.erb", "db/migrate/create_users.rb")
end

def create_user_model

def create_user_model
  copy_file("user.rb", "app/models/user.rb")
end

def new_shopify_cli_app?

def new_shopify_cli_app?
  options["new_shopify_cli_app"]
end

def next_migration_number(dir)

for generating a timestamp when using `create_migration`
def next_migration_number(dir)
  ActiveRecord::Generators::Base.next_migration_number(dir)
end

def rails_migration_version

def rails_migration_version
  Rails.version.match(/\d\.\d/)[0]
end

def update_shopify_app_initializer

def update_shopify_app_initializer
  gsub_file("config/initializers/shopify_app.rb", "ShopifyApp::InMemoryUserSessionStore", "User")
end