content: package Trip.Mate.Trip.controller;
  
  import Trip.Mate.Trip.model.User;
  import Trip.Mate.Trip.service.UserService;
  import jakarta.servlet.http.HttpServletResponse;
  import lombok.RequiredArgsConstructor;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.*;
  
  import java.util.List;
  import java.util.Optional;
  
  @RestController
  @RequestMapping("/api/users")
  @RequiredArgsConstructor
  public class UserController {
  
      private final UserService userService;
  
      // Register a new user
      @PostMapping("/register")
      public ResponseEntity<String> registerUser(@RequestBody User user) {
          userService.userRegister(user);
          return new ResponseEntity<>("User registered successfully", HttpStatus.CREATED);
      }
  
      // Get all users
      @GetMapping
      public ResponseEntity<List<User>> getAllUsers() {
          List<User> users = userService.allDetails();
          return new ResponseEntity<>(users, HttpStatus.OK);
      }
  
      // Get a user by ID
      @GetMapping("/{id}")
      public ResponseEntity<User> getUserById(@PathVariable int id) {
          Optional<User> user = userService.getUserById(id);
          return user.map(ResponseEntity::ok).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
      }
  
      // Update a user by ID
      @PutMapping("/{id}")
      public ResponseEntity<User> updateUser(@PathVariable int id, @RequestBody User updatedUser) {
          try {
              User user = userService.updateUser(id, updatedUser);
              return new ResponseEntity<>(user, HttpStatus.OK);
          } catch (RuntimeException e) {
              return new ResponseEntity<>(HttpStatus.NOT_FOUND);
          }
      }
  
      // Delete a user by ID
      @DeleteMapping("/{id}")
      public ResponseEntity<String> deleteUser(@PathVariable int id) {
          try {
              userService.deleteUser(id);
              return new ResponseEntity<>("User deleted successfully", HttpStatus.OK);
          } catch (RuntimeException e) {
              return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
          }
      }
  
      // Verify user by email and password
      @PostMapping("/verify")
      public ResponseEntity<User> verifyUser(@RequestParam String email, @RequestParam String pass, HttpServletResponse response) {
          User user = userService.verifyUser(email, pass,response);
          if (user != null) {
              return new ResponseEntity<>(user, HttpStatus.OK);
          } else {
              return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
          }
      }
  }
  