package ru.soune.nocopy.entity.payout;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.*;
import ru.soune.nocopy.entity.payout.convertor.CardNumberEncryptor;

@Entity
@DiscriminatorValue("CARD")
@NoArgsConstructor
@AllArgsConstructor
@Setter @Getter
public class CardPayoutMethod extends PayoutMethod {
    @Convert(converter = CardNumberEncryptor.class)
    @Column(name = "card_number", nullable = false)
    private String cardNumber;

    @Column(name = "card_hash", unique = true)
    private String cardHash;

    @Override
    public String getDisplayName() {
        return "Card: " + getMaskedCardNumber();
    }

    @Override
    public String getMaskedDetails() {
        return getMaskedCardNumber();
    }

    private String getMaskedCardNumber() {
        if (cardNumber == null || cardNumber.length() < 4) return "";
        return "****" + cardNumber.substring(cardNumber.length() - 4);
    }
}
