package com.banesco.application.rest.controllers;

import com.banesco.application.UpdateCardStatusRequest;
import com.banesco.commons.config.AppConf;
import com.banesco.commons.soap.client.apidebitcardoutappsvc.BlockUnblockDebitCardRs;
import com.banesco.domain.ports.inbound.UpdateCardStatusUseCase;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;


@Tag(name = "API Dominio - Actualización de Estatus de Tarjetas")
@Path("/card/status/update")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Slf4j
public class UpdateCardController {


    private final UpdateCardStatusUseCase updateCardStatusUseCase;

    private final AppConf appConf;

    @Inject
    public UpdateCardController(AppConf appConf,
                                UpdateCardStatusUseCase updateCardStatusUseCase) {
        this.appConf = appConf;
        this.updateCardStatusUseCase = updateCardStatusUseCase;
    }


    @PUT()
    @Operation(summary = "updateStatus", description = "Cambio de estatus de tarjeta")
    public Response updateStatus(
            UpdateCardStatusRequest request
    ) {

        log.info("[RQ]: {}", appConf.getJsonHelper().getJsonFromObject(request));
        BlockUnblockDebitCardRs response = updateCardStatusUseCase.executeUpdate(request);
        log.info("[RS]: {}", appConf.getJsonHelper().getJsonFromObject(response));
        return Response.ok().entity(response).build();
    }


}


