// Path: src/main/java/com/parrit/DTOs/PersonDTO.java
// @Getter
// @Setter
// @EqualsAndHashCode
// public class PersonDTO {
// 
//     private long id;
// 
//     @NotNull(message = "Hey! This name needs to be between 1 and 32 characters.")
//     @Size(min = 1, max = 32, message = "Hey! This name needs to be between 1 and 32 characters.")
//     private String name;
// 
// }
// 
// Path: src/main/java/com/parrit/entities/PairingBoard.java
// @Entity
// @Table(name = "pairing_board",
//         indexes = {
//                 @Index(name = "pairing_board_pkey", unique = true, columnList = "id")
//         }
// )
// @Getter
// @Setter
// @NoArgsConstructor
// @EqualsAndHashCode
// @ToString
// public class PairingBoard {
// 
//     @Id
//     @Column(name = "id", nullable = false)
//     @ColumnDefault("nextval('pairing_board_id_seq')")
//     @SequenceGenerator(name = "pairing_board_id_gen", sequenceName = "pairing_board_id_seq", initialValue = 1, allocationSize = 1)
//     @GeneratedValue(generator = "pairing_board_id_gen", strategy = GenerationType.SEQUENCE)
//     private long id;
// 
//     @Column(name = "name", nullable = false, length = 255)
//     private String name;
// 
//     @Column(name = "exempt", nullable = false)
//     private boolean exempt;
// 
//     @OneToMany
//     @JoinColumn(name = "pairing_board_id", nullable = true, foreignKey = @ForeignKey(name = "pairing_board_id_fk"))
//     private List<Person> people = new ArrayList<>();
// 
//     @OneToMany(cascade = CascadeType.ALL)
//     @JoinColumn(name = "pairing_board_id", nullable = false, foreignKey = @ForeignKey(name = "pairing_board_id_fk"))
//     private List<Role> roles = new ArrayList<>();
// 
//     public PairingBoard(String name, boolean exempt, List<Person> people, List<Role> roles) {
//         this.name = name;
//         this.exempt = exempt;
//         this.people = people;
//         this.roles = roles;
//     }
// 
// }
// 
// Path: src/main/java/com/parrit/exceptions/PairingBoardPositionNotFoundException.java
// public class PairingBoardPositionNotFoundException extends RuntimeException {
// 
//     public PairingBoardPositionNotFoundException(String msg) {
//         super(msg);
//     }
// }
// 
// Path: src/main/java/com/parrit/repositories/ProjectRepository.java
// @Repository
// public interface ProjectRepository extends JpaRepository<Project, Long> {
// 
//     Optional<Project> findByName(String name);
// 
// }


import com.parrit.DTOs.PersonDTO;
import com.parrit.DTOs.PersonPositionDTO;
import com.parrit.DTOs.ProjectDTO;
import com.parrit.entities.PairingBoard;
import com.parrit.entities.Person;
import com.parrit.entities.Project;
import com.parrit.exceptions.PairingBoardPositionNotFoundException;
import com.parrit.exceptions.PersonNotFoundException;
import com.parrit.repositories.ProjectRepository;
import com.parrit.transformers.ProjectTransformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Stream;
        Person person = listWithPerson.stream()
                .filter(p -> p.getId() == personId)
                .findFirst()
                .get();
        listWithPerson.remove(person);

        if (personPositionDTO.isFloating()) {
            savedProject.getPeople().add(person);
        } else {
            PairingBoard matchingPairingBoard = savedProject.getPairingBoards().stream()
                    .filter(pb -> pb.getId() == personPositionDTO.getPairingBoardId())
                    .findFirst()
                    .orElseThrow(() -> new PairingBoardPositionNotFoundException("Keeaa!? That pairing board doesn't seem to exist."));

            matchingPairingBoard.getPeople().add(person);
        }

        Project updatedProject = projectRepository.save(savedProject);
        return ProjectTransformer.transform(updatedProject);
    }

    @PreAuthorize("@authorizationService.canAccessProject(principal, #projectId)")
    @DeleteMapping(path = "/api/project/{projectId}/person/{personId}")
    public ProjectDTO deletePerson(@PathVariable long projectId, @PathVariable long personId) {
        Project savedProject = projectRepository.findById(projectId).get();

        Stream<List<Person>> floatingPeople = Stream.of(savedProject.getPeople());
        Stream<List<Person>> pairingBoardPeople = savedProject.getPairingBoards().stream().map(PairingBoard::getPeople);
        List<Person> listWithPerson = Stream.concat(floatingPeople, pairingBoardPeople)
                .filter(ppl -> ppl.stream().anyMatch(p -> p.getId() == personId))
// Path: src/main/java/com/parrit/DTOs/PersonDTO.java
// @Getter
// @Setter
// @EqualsAndHashCode
// public class PersonDTO {
// 
//     private long id;
// 
//     @NotNull(message = "Hey! This name needs to be between 1 and 32 characters.")
//     @Size(min = 1, max = 32, message = "Hey! This name needs to be between 1 and 32 characters.")
//     private String name;
// 
// }
// 
// Path: src/main/java/com/parrit/entities/PairingBoard.java
// @Entity
// @Table(name = "pairing_board",
//         indexes = {
//                 @Index(name = "pairing_board_pkey", unique = true, columnList = "id")
//         }
// )
// @Getter
// @Setter
// @NoArgsConstructor
// @EqualsAndHashCode
// @ToString
// public class PairingBoard {
// 
//     @Id
//     @Column(name = "id", nullable = false)
//     @ColumnDefault("nextval('pairing_board_id_seq')")
//     @SequenceGenerator(name = "pairing_board_id_gen", sequenceName = "pairing_board_id_seq", initialValue = 1, allocationSize = 1)
//     @GeneratedValue(generator = "pairing_board_id_gen", strategy = GenerationType.SEQUENCE)
//     private long id;
// 
//     @Column(name = "name", nullable = false, length = 255)
//     private String name;
// 
//     @Column(name = "exempt", nullable = false)
//     private boolean exempt;
// 
//     @OneToMany
//     @JoinColumn(name = "pairing_board_id", nullable = true, foreignKey = @ForeignKey(name = "pairing_board_id_fk"))
//     private List<Person> people = new ArrayList<>();
// 
//     @OneToMany(cascade = CascadeType.ALL)
//     @JoinColumn(name = "pairing_board_id", nullable = false, foreignKey = @ForeignKey(name = "pairing_board_id_fk"))
//     private List<Role> roles = new ArrayList<>();
// 
//     public PairingBoard(String name, boolean exempt, List<Person> people, List<Role> roles) {
//         this.name = name;
//         this.exempt = exempt;
//         this.people = people;
//         this.roles = roles;
//     }
// 
// }
// 
// Path: src/main/java/com/parrit/exceptions/PairingBoardPositionNotFoundException.java
// public class PairingBoardPositionNotFoundException extends RuntimeException {
// 
//     public PairingBoardPositionNotFoundException(String msg) {
//         super(msg);
//     }
// }
// 
// Path: src/main/java/com/parrit/repositories/ProjectRepository.java
// @Repository
// public interface ProjectRepository extends JpaRepository<Project, Long> {
// 
//     Optional<Project> findByName(String name);
// 
// }


// Path: src/main/java/com/parrit/controllers/PersonController.java
import com.parrit.DTOs.PersonDTO;
import com.parrit.DTOs.PersonPositionDTO;
import com.parrit.DTOs.ProjectDTO;
import com.parrit.entities.PairingBoard;
import com.parrit.entities.Person;
import com.parrit.entities.Project;
import com.parrit.exceptions.PairingBoardPositionNotFoundException;
import com.parrit.exceptions.PersonNotFoundException;
import com.parrit.repositories.ProjectRepository;
import com.parrit.transformers.ProjectTransformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Stream;

        Person person = listWithPerson.stream()
                .filter(p -> p.getId() == personId)
                .findFirst()
                .get();
        listWithPerson.remove(person);

        if (personPositionDTO.isFloating()) {
            savedProject.getPeople().add(person);
        } else {
            PairingBoard matchingPairingBoard = savedProject.getPairingBoards().stream()
                    .filter(pb -> pb.getId() == personPositionDTO.getPairingBoardId())
                    .findFirst()
                    .orElseThrow(() -> new PairingBoardPositionNotFoundException("Keeaa!? That pairing board doesn't seem to exist."));

            matchingPairingBoard.getPeople().add(person);
        }

        Project updatedProject = projectRepository.save(savedProject);
        return ProjectTransformer.transform(updatedProject);
    }

    @PreAuthorize("@authorizationService.canAccessProject(principal, #projectId)")
    @DeleteMapping(path = "/api/project/{projectId}/person/{personId}")
    public ProjectDTO deletePerson(@PathVariable long projectId, @PathVariable long personId) {
        Project savedProject = projectRepository.findById(projectId).get();

        Stream<List<Person>> floatingPeople = Stream.of(savedProject.getPeople());
        Stream<List<Person>> pairingBoardPeople = savedProject.getPairingBoards().stream().map(PairingBoard::getPeople);
        List<Person> listWithPerson = Stream.concat(floatingPeople, pairingBoardPeople)
                .filter(ppl -> ppl.stream().anyMatch(p -> p.getId() == personId))
                .findFirst()