package com.ikon.projectmanagement.entity;

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

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

import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

@Entity
@Table(name = "product_ps_resource_allocation")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ProductPSResourceAllocation {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    private UUID id;
    private String resourceType;
    private String role;
    private Integer gradeId;
    private String employeeName;
    private String taskName;
    private String resourceId;
    private Long taskId;

    // Storing FTE allotments per month: {"Aug_2025": 0.9, "Sep_2025": 0.5}
    @ElementCollection
    @CollectionTable(
        name = "product_ps_resource_allocation_months",
        joinColumns = @JoinColumn(name = "allocation_id")
    )
    @MapKeyColumn(name = "month")
    @Column(name = "fte_value")
    private Map<String, Double> allocation;

    @JdbcTypeCode(SqlTypes.JSON)
    @Column(columnDefinition = "json", nullable = true)
    private Map<String, Map<String, Object>> detailedAllocation;

    @ManyToOne
    @JoinColumn(name = "deal_identifier")
    private ProductOfProject productPS;
}
