// Path: friendly-id/src/main/java/com/devskiller/friendly_id/FriendlyId.java
// public class FriendlyId {
// 
// 	/**
// 	 * Create FriendlyId id
// 	 *
// 	 * @return Friendly Id encoded UUID
// 	 */
// 	public static String createFriendlyId() {
// 		return Url62.encode(UUID.randomUUID());
// 	}
// 
// 	/**
// 	 * Encode UUID to FriendlyId id
// 	 *
// 	 * @param uuid UUID to be encoded
// 	 * @return Friendly Id encoded UUID
// 	 */
// 	public static String toFriendlyId(UUID uuid) {
// 		return Url62.encode(uuid);
// 	}
// 
// 	/**
// 	 * Decode Friendly Id to UUID
// 	 *
// 	 * @param friendlyId encoded UUID
// 	 * @return decoded UUID
// 	 */
// 	public static UUID toUuid(String friendlyId) {
// 		return Url62.decode(friendlyId);
// 	}
// 
// }
// 
// Path: friendly-id-samples/friendly-id-contracts/src/main/java/com/devskiller/friendly_id/sample/contracts/domain/Foo.java
// @Data
// @AllArgsConstructor
// public class Foo {
// 
// 	private UUID id;
// 	private String name;
// 
// }


import com.devskiller.friendly_id.FriendlyId;
import com.devskiller.friendly_id.sample.contracts.domain.Foo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.hateoas.server.ExposesResourceFor;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.lang.invoke.MethodHandles;
import java.util.UUID;
package com.devskiller.friendly_id.sample.contracts;




@RestController
@ExposesResourceFor(FooResource.class)
@RequestMapping("/foos")
public class FooController {

	private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

	private final EntityLinks entityLinks;
	private final FooResourceAssembler assembler;

	public FooController(EntityLinks entityLinks) {
		this.entityLinks = entityLinks;
		this.assembler = new FooResourceAssembler();
	}

	@GetMapping("/{id}")
	public FooResource get(@PathVariable UUID id) {
		log.info("Get {}", id);
		Foo foo = new Foo(id, "Foo");
		return assembler.toModel(foo);
	}

	@PutMapping("/{id}")
	public HttpEntity<FooResource> update(@PathVariable UUID id, @RequestBody FooResource fooResource) {
		log.info("Update {} : {}", id, fooResource);
		Foo entity = new Foo(fooResource.getUuid(), fooResource.getName());
		return ResponseEntity.ok(assembler.toModel(entity));
	}

	@PostMapping
	public HttpEntity<FooResource> create(@RequestBody FooResource fooResource) {
		HttpHeaders headers = new HttpHeaders();
		Foo entity = new Foo(fooResource.getUuid(), "Foo");

		// ...

// Path: friendly-id/src/main/java/com/devskiller/friendly_id/FriendlyId.java
// public class FriendlyId {
// 
// 	/**
// 	 * Create FriendlyId id
// 	 *
// 	 * @return Friendly Id encoded UUID
// 	 */
// 	public static String createFriendlyId() {
// 		return Url62.encode(UUID.randomUUID());
// 	}
// 
// 	/**
// 	 * Encode UUID to FriendlyId id
// 	 *
// 	 * @param uuid UUID to be encoded
// 	 * @return Friendly Id encoded UUID
// 	 */
// 	public static String toFriendlyId(UUID uuid) {
// 		return Url62.encode(uuid);
// 	}
// 
// 	/**
// 	 * Decode Friendly Id to UUID
// 	 *
// 	 * @param friendlyId encoded UUID
// 	 * @return decoded UUID
// 	 */
// 	public static UUID toUuid(String friendlyId) {
// 		return Url62.decode(friendlyId);
// 	}
// 
// }
// 
// Path: friendly-id-samples/friendly-id-contracts/src/main/java/com/devskiller/friendly_id/sample/contracts/domain/Foo.java
// @Data
// @AllArgsConstructor
// public class Foo {
// 
// 	private UUID id;
// 	private String name;
// 
// }


// Path: friendly-id-samples/friendly-id-contracts/src/main/java/com/devskiller/friendly_id/sample/contracts/FooController.java
import com.devskiller.friendly_id.FriendlyId;
import com.devskiller.friendly_id.sample.contracts.domain.Foo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.hateoas.server.ExposesResourceFor;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.lang.invoke.MethodHandles;
import java.util.UUID;

package com.devskiller.friendly_id.sample.contracts;




@RestController
@ExposesResourceFor(FooResource.class)
@RequestMapping("/foos")
public class FooController {

	private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

	private final EntityLinks entityLinks;
	private final FooResourceAssembler assembler;

	public FooController(EntityLinks entityLinks) {
		this.entityLinks = entityLinks;
		this.assembler = new FooResourceAssembler();
	}

	@GetMapping("/{id}")
	public FooResource get(@PathVariable UUID id) {
		log.info("Get {}", id);
		Foo foo = new Foo(id, "Foo");
		return assembler.toModel(foo);
	}

	@PutMapping("/{id}")
	public HttpEntity<FooResource> update(@PathVariable UUID id, @RequestBody FooResource fooResource) {
		log.info("Update {} : {}", id, fooResource);
		Foo entity = new Foo(fooResource.getUuid(), fooResource.getName());
		return ResponseEntity.ok(assembler.toModel(entity));
	}

	@PostMapping
	public HttpEntity<FooResource> create(@RequestBody FooResource fooResource) {
		HttpHeaders headers = new HttpHeaders();
		Foo entity = new Foo(fooResource.getUuid(), "Foo");

		// ...

		headers.setLocation(entityLinks.linkToItemResource(FooResource.class, FriendlyId.toFriendlyId(entity.getId())).toUri());