package com.sc.sicanet.migracion_sicanet.controller;

import java.util.Optional;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sc.sicanet.migracion_sicanet.entity.Prestamos;
import com.sc.sicanet.migracion_sicanet.service.PrestamosServiceImpl;

@RestController
@RequestMapping("/prestamos")
public class PrestamosController {

    final private PrestamosServiceImpl prestamosService;

    public PrestamosController(PrestamosServiceImpl prestamosService) {
        this.prestamosService = prestamosService;
    }

    @PostMapping()
    public Prestamos postAbono(@RequestParam("cuentaSTP") String cuentaSTP) {
        System.out.println("cuentaSTP -> " + cuentaSTP);
        Optional<Prestamos> prestamo = prestamosService.findByCuentaSTP(cuentaSTP);

        //System.out.println("prestamo control -> " + prestamo.get().getControl());
        
        return prestamo.isPresent() ? prestamo.get() : new Prestamos();
    }
}
