package com.realnet.password_generator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/v1/password-generator")
public class PasswordGeneratorController {

    @Autowired
    private PasswordGeneratorService passwordGeneratorService;

    @PostMapping("/generate")
    public ResponseEntity<PasswordGenerationResponse> generatePassword(@Valid @RequestBody PasswordGenerationRequest request) {
        PasswordGenerationResponse response = passwordGeneratorService.generatePassword(request);
        if (response.isSuccess()) {
            return ResponseEntity.ok(response);
        } else {
            return ResponseEntity.badRequest().body(response);
        }
    }
}
