package com.server.api.controller;

import com.server.api.models.User;
import com.server.api.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired private AuthService authService;

    @PostMapping("/signup")
    public ResponseEntity<String> signup(@RequestBody User user){
        if (authService.signUp(user)){
            return ResponseEntity.ok("SignUp successful!");
        }else{
            return ResponseEntity.status(400).body("SignUp failed. Please try again.");
        }
    }

    @PostMapping("/signin")
    public ResponseEntity<String> signin(@RequestBody User user){
        if (authService.signIn(user)){
            return ResponseEntity.ok("SignIn successful!");
        }else{
            return ResponseEntity.status(400).body("SignIn failed. Please try again.");
        }
    }
}
