if Rails.env.development? || Rails.env.test? || Rails.env.review?
  require "factory_bot"

  namespace :dev do
    desc "Sample data for local development environment"
    task :prime, [:skip_reset_db] => [:environment] do |_task, args|
      include FactoryBot::Syntax::Methods

      Rake::Task["db:setup"].invoke unless args[:skip_reset_db].present?

      data = {
        account_name: "Dev Account",
        account_plan: "me_suite",
        user_email: "dev@test.com",
        user_password: "password",
      }

      # Account and Admin User
      dev_account = create(:account, name: data.fetch(:account_name), plan_uid: data.fetch(:account_plan))
      user = Oath::Services::SignUp.new(email: data.fetch(:user_email), password: data.fetch(:user_password), admin: true).perform

      dev_account.account_auths.create(user: user, role: :account_manager)
      # Add Sample Project
      dev_account.projects << SampleProject.new
      dev_account.projects.first.save!

      # Enable all sections for the sample project 
      project = dev_account.projects.first
      project.settings(:features).update!({
        acquired_media_release: true,
        appearance_release: true,
        location_release: true,
        material_release: true,
        music_release: true,
        talent_release: true,
        video_analysis: true,
      })

      # Add a ContractTemplate
      create(:contract_template, project: project)
    end

    desc "Poll videos with pending analysis for updates" 
    task poll_for_analysis_updates: :environment do
      puts "Polling videos with pending analysis for updates..."
      PendingAnalysis.poll
      puts "Done."
    end
  end
end
