api.deal do
  api.id @deal.id
  api.name @deal.name
  api.price @deal.price
  api.currency @deal.currency
  api.price_type @deal.price_type
  api.duration @deal.duration
  api.probability @deal.probability
  api.due_date @deal.due_date
  api.background @deal.background
  api.project(:id => @deal.project_id, :name => @deal.project.name) unless @deal.project.nil?
  api.status(:id => @deal.status_id, :name => @deal.status.name) unless @deal.status.nil?
  api.category(:id => @deal.category_id, :name => @deal.category.name) unless @deal.category.nil?
  api.author(:id => @deal.author_id, :name => @deal.author.name) unless @deal.author.nil?
  api.contact(:id => @deal.contact_id, :name => @deal.contact.name) unless @deal.contact.nil?
  api.assigned_to(:id => @deal.assigned_to_id, :name => @deal.assigned_to.name) unless @deal.assigned_to.nil?
  render_api_custom_values @deal.custom_field_values, api
  api.created_on @deal.created_on
  api.updated_on @deal.updated_on

  api.array :related_contacts do
    @deal.related_contacts.each do |contact|
      api.contact(:id => contact.id, :name => contact.name)
    end
  end if @deal.related_contacts.any?

  if authorize_for(:notes, :show)
    api.array :notes do
      @deal.notes.each do |note|
        api.note do
          api.id note.id
          api.content note.content
          api.type_id note.type_id
          api.author(:id => note.author_id, :name => note.author.name) unless note.author.nil?
          api.created_on note.created_on
          api.updated_on note.updated_on
        end
      end
    end if include_in_api_response?('notes') && @deal.notes.present? && User.current.allowed_to?(:view_deals, @project)
  end


  call_hook(:api_deals_show)

end
