Given(/^I have a new project(?: for label (.*))?$/) do |label_id|
  if label_id.nil? || label_id == "7123"
    label_id = 7123
    artist_id = 578_144
  else
    artist_id = 71_879
  end
  session_token = Support::Services::GrassAuth.instance.workstation_session_token("label_#{label_id}")
  code = Time.stamp
  result = Support::Services::OwsProjectManager.create_project(
    artist_id, code, "Project " + code, session_token
  )
  @project_id = result["project_id"]
end

Given(/^I have no projections on product (\d+)$/) do |product_id|
  session_token = Support::Services::GrassAuth.instance.workstation_session_token("label_7123")
  result = Support::Services::OwsSalesGoals.get_digital_projections(
    product_id, session_token
  )

  if result["projections"]
    result["projections"].each do |projection|
      Support::Services::OwsSalesGoals.delete_projections(
        product_id, projection["id"], session_token
      )
    end
  end
end

Given(/^I have United States projections and global totals on my product$/) do
  step "I have United States projections and global totals on product #{@product_id}"
end

Given(/^I have United States projections and global totals on product (\d+)$/) do |product_id|
  session_token = Support::Services::GrassAuth.instance.workstation_session_token("label_7123")
  # territory ID 1 is United States
  Support::Services::OwsSalesGoals.create_projections(product_id, session_token, 1)
  Support::Services::OwsSalesGoals.create_global_totals(product_id, session_token)
end

Given(/^I have a new project and digital product for label (.*)$/) do |label_id|
  step "I have a new project for label #{label_id}"
  session_token = Support::Services::GrassAuth.instance.workstation_session_token("label_" + label_id)
  ows_product_digital = Support::Services::OwsProductDigital
  product_response = ows_product_digital.create_product(@project_id, session_token, label_id)
  @upc = product_response["upc"]
  @product_id = product_response["product_id"]
end
