text: import TypeChecking from "../support/TypeChecking";
  import { CharacterService } from "./CharacterService";
  import { STARSHIPS_CATEGORY } from "./CategoryService";
  import { FilmService } from "./FilmService";
  import {
  	createSingleEntityRequest,
  	createMultipleEntityRequest,
  	createProcessEntity,
  } from "./EntityService";
  
  const getDto = (starship, id, imageUrl, pendingPromises) => {
  	return {
  		pendingPromises,
  		entity: {
  			id,
  			category: STARSHIPS_CATEGORY,
  			imageUrl,
  			url: starship.url,
  			name: starship.name,
  			traits: {
  				model: starship.model,
  				manufacturer: starship.manufacturer,
  				cost_in_credits: starship.cost_in_credits,
  				length: starship.length,
  				max_atmosphering_speed: starship.max_atmosphering_speed,
  				crew: starship.crew,
  				passengers: starship.passengers,
  				cargo_capacity: starship.cargo_capacity,
  				consumables: starship.consumables,
  				hyperdrive_rating: starship.hyperdrive_rating,
  				MGLT: starship.MGLT,
  				starship_class: starship.starship_class,
  			},
  			relationships: {
  				characters: [],
  				films: [],
  			},
  		},
  	};
  };
  
  const getUrl = (id) => {
  	if (!TypeChecking.isNull(id)) {
  		return `https://starwars-visualguide.com/assets/img/vehicles/${id}.jpg`;
  	}
  	return "";
  };
  
  const getRelationshipsPromises = (starship) => {
  	const pendingPromises = [];
  	// Don't use "to" so any exception thrown can be captured by the caller
  	if (TypeChecking.isArray(starship.pilots)) {
  		pendingPromises.push(CharacterService.getItems(starship.pilots, false));
  	}
  	if (TypeChecking.isArray(starship.films)) {
  		pendingPromises.push(FilmService.getItems(starship.films, false));
  	}
  
  	return pendingPromises;
  };
  
  export const StarshipService = {
  	processEntity: createProcessEntity(
  		getUrl,
  		getRelationshipsPromises,
  		getDto,
  		STARSHIPS_CATEGORY
  	),
  	getSingleItem: createSingleEntityRequest(getUrl, getRelationshipsPromises, getDto),
  	getItems: createMultipleEntityRequest(getUrl, getRelationshipsPromises, getDto),
  };
  