package de.szut.casino.deposit;

import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.checkout.Session;
import com.stripe.param.InvoiceItemCreateParams;
import com.stripe.param.PriceCreateParams;
import com.stripe.param.checkout.SessionCreateParams;
import de.szut.casino.deposit.dto.AmountDto;
import de.szut.casino.deposit.dto.SessionIdDto;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties;
import org.springframework.http.HttpHeaders;
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.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DepositController {

    @Value("${stripe.secret.key}")
    private String stripeKey;

    @PostMapping("/deposit/checkout")
    public ResponseEntity<SessionIdDto> checkout(
            @RequestBody @Valid AmountDto amountDto,
            @RequestHeader("Origin") String origin
    ) throws StripeException {
        Stripe.apiKey = stripeKey;

        SessionCreateParams params = SessionCreateParams.builder()
                .addLineItem(SessionCreateParams.LineItem.builder()
                        .setAmount((long) amountDto.getAmount() * 100)
                        .setCurrency("EUR")
                        .setQuantity(1L)
                        .setName("Einzahlung")
                        .build())
                .setSuccessUrl(origin+"/deposit/success")
                .setMode(SessionCreateParams.Mode.PAYMENT)
                .build();

        Session session = Session.create(params);

        return ResponseEntity.ok(new SessionIdDto(session.getId()));
    }
}

