<commit_before>package services.form;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import domain.FeePayment;
import domain.RouteOffer;
import domain.ShipmentOffer;
import domain.form.FeePaymentForm;
import services.FeePaymentService;
import services.RouteOfferService;
import services.RouteService;
import services.ShipmentOfferService;

@Service
@Transactional
public class FeePaymentFormService {

	// Supporting services ----------------------------------------------------

	@Autowired
	private FeePaymentService feePaymentService;
	
	@Autowired
	private RouteOfferService routeOfferService;
	
	@Autowired
	private ShipmentOfferService shipmentOfferService;
	
	@Autowired
	private RouteService routeService;
	
	// Constructors -----------------------------------------------------------

	public FeePaymentFormService() {
		super();
	}
	
	// Simple CRUD methods ----------------------------------------------------


	public FeePaymentForm create(int type, int id, int sizePriceId, double amount, String description, int shipmentId) {
		FeePaymentForm result;
		
		result = new FeePaymentForm();
		
		result.setType(type);
		
		/**
		 * Type == 1 -> Contract a route
		 * Type == 2 -> Create a routeOffer
		 * Type == 3 -> Accept a shipmentOffer
		 */
		switch (type) {
		case 1:
			result.setId(id);
			result.setSizePriceId(sizePriceId);
			break;
			
		case 2:
			result.setId(id);
			result.setAmount(amount);
			result.setDescription(description);
			result.setShipmentId(shipmentId);
			break;
			
		case 3:
			ShipmentOffer shipmentOffer;
			
			shipmentOffer = shipmentOfferService.findOne(id);
			
			result.setId(shipmentOffer.getShipment().getId());
			result.setOfferId(id);
			break;

		default:
			break;
		}
		
		
		return result;
	}
	
	public FeePayment reconstruct(FeePaymentForm feePaymentForm) {
		FeePayment result;
		RouteOffer routeOffer;
		
		result = feePaymentService.create();
		
		switch (feePaymentForm.getType()) {
		case 1:
			routeOffer = routeService.contractRoute(feePaymentForm.getId(), feePaymentForm.getSizePriceId());
			feePaymentForm.setOfferId(routeOffer.getId());
			
			result.setRouteOffer(routeOffer);
			result.setAmount(routeOffer.getAmount());
			result.setCreditCard(feePaymentForm.getCreditCard());
			result.setCarrier(routeOffer.getRoute().getCreator());
			break;
			<commit_msg>Solución error no poder contratar ruta sin contraoferta<commit_after>package services.form;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import domain.FeePayment;
import domain.RouteOffer;
import domain.ShipmentOffer;
import domain.form.FeePaymentForm;
import services.FeePaymentService;
import services.RouteOfferService;
import services.RouteService;
import services.ShipmentOfferService;

@Service
@Transactional
public class FeePaymentFormService {

	// Supporting services ----------------------------------------------------

	@Autowired
	private FeePaymentService feePaymentService;
	
	@Autowired
	private RouteOfferService routeOfferService;
	
	@Autowired
	private ShipmentOfferService shipmentOfferService;
	
	@Autowired
	private RouteService routeService;
	
	// Constructors -----------------------------------------------------------

	public FeePaymentFormService() {
		super();
	}
	
	// Simple CRUD methods ----------------------------------------------------


	public FeePaymentForm create(int type, int id, int sizePriceId, double amount, String description, int shipmentId) {
		FeePaymentForm result;
		
		result = new FeePaymentForm();
		
		result.setType(type);
		
		/**
		 * Type == 1 -> Contract a route
		 * Type == 2 -> Create a routeOffer
		 * Type == 3 -> Accept a shipmentOffer
		 */
		switch (type) {
		case 1:
			result.setId(id);
			result.setSizePriceId(sizePriceId);
			result.setAmount(0.1); // Posteriormente se resetear al valor oportuno
			break;
			
		case 2:
			result.setId(id);
			result.setAmount(amount);
			result.setDescription(description);
			result.setShipmentId(shipmentId);
			break;
			
		case 3:
			ShipmentOffer shipmentOffer;
			
			shipmentOffer = shipmentOfferService.findOne(id);
			
			result.setId(shipmentOffer.getShipment().getId());
			result.setOfferId(id);
			result.setAmount(0.1);
			break;

		default:
			break;
		}
		
		
		return result;
	}
	
	public FeePayment reconstruct(FeePaymentForm feePaymentForm) {
		FeePayment result;
		RouteOffer routeOffer;
		
		result = feePaymentService.create();
		
		switch (feePaymentForm.getType()) {
		case 1:
			routeOffer = routeService.contractRoute(feePaymentForm.getId(), feePaymentForm.getSizePriceId());
			feePaymentForm.setOfferId(routeOffer.getId());
			
			result.setRouteOffer(routeOffer);
			result.setAmount(routeOffer.getAmount());
			result.setCreditCard(feePaymentForm.getCreditCard());
			result.setCarrier(routeOffer.getRoute().getCreator());
			break;
			
{'fraction_non_alphanumeric': 0.15372487189594009, 'fraction_numerical': 0.0035474970437524636, 'mean_word_length': 3.26112510495382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6341773', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1443, 'n_words': 293}