package org.jpos.tcpay.db.entity;

import com.sleepycat.je.utilint.CollectionUtils;
import lombok.Data;
import lombok.experimental.Accessors;
import org.jpos.tcpay.acquirer.AcquirerNames;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Data
@Accessors(chain = true)
@Entity
@Table(name = "acquirer_terminal")
public class AcquirerTerminal {
    @Id
    @GeneratedValue
    long id;

    @OneToOne
    @JoinColumn(name = "acquirer_id")
    Acquirer acquirer;

    @Column(name="terminalid")
    String terminalId;

    @OneToOne
    @JoinColumn(name = "acquirer_merchant_id")
    AcquirerMerchant acquirerMerchant;

    @ManyToMany(mappedBy = "acquirerTerminals")
    List<PosTerminal> posTerminals = new ArrayList<>();

    @Override
    public String toString() {
        return "acquirer_id:" + acquirer + "\n"
                + "terminalId:" + terminalId + "\n"
                + "acquirerMerchant:" + (Objects.isNull(acquirerMerchant) ? "null" : acquirerMerchant.merchantId)
                + "posTerminals:" + (Objects.isNull(posTerminals) ? "null"
                            : posTerminals.stream().map(PosTerminal::getTerminalid).collect(Collectors.toList()).toString());
    }
}
