package com.ikon.projectmanagement.entity;

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

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

@Entity
@Table(name = "working_days")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WorkingDaysEntity {

    @Id
    @Column(name = "working_id")
    private UUID workingId;

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

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

    public void addWorkingDaysDetail(WorkingDaysDetailsEntity detail) {
        detail.setWorkingDaysEntity(this);
        this.workingDaysDetails.put(detail.getMonth(), detail);
    }
}