<?php

class WPML_TP_API_TF_Ratings extends WPML_TP_Abstract_API {

	protected function get_endpoint_uri() {
		return '/batches/{batch_id}/jobs/{original_file_id}/ratings';
	}

	protected function is_authenticated() {
		return true;
	}

	public function send( WPML_TF_Feedback $feedback ) {
		$params = array(
			'batch_id'         => $this->tp_client->get_tm_jobs()->get_batch_id( $feedback->get_job_id() ),
			'original_file_id' => $this->get_original_file_id(
				$feedback->get_job_id(),
				$feedback->get_document_information()->get_source_id()
			),
			'rating'           => array(
				'rating' => $feedback->get_rating(),
			),
		);

		$response = $this->post( $params );

		if ( isset( $response->rating->id ) ) {
			return (int) $response->rating->id;
		}

		return false;
	}
}
