package com.ikon.projectmanagement.entity;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Table(name = "fx_rates_v2")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FxRateEntity {

    @Id
    @Column(name = "fx_rate_id")
    private UUID fxRateId;

    @Column(name = "account_identifier")
    private UUID accountIdentifier;

    @OneToMany(mappedBy = "fxRateEntity", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @MapKey(name = "currencyId")
    @Builder.Default
    @ToString.Exclude
    @EqualsAndHashCode.Exclude
    private Map<String, FxRateDetailsEntity> fxRateDetails = new HashMap<>();

    public void addFxRateDetail(FxRateDetailsEntity detail) {
        detail.setFxRateEntity(this);
        this.fxRateDetails.put(detail.getCurrencyId(), detail);
    }
}