package com.ikon.projectmanagement.entity;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Entity
@Table(name = "project_schedule", uniqueConstraints = {
        @UniqueConstraint(columnNames = "project_identifier")
})
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ProjectSchedule {

    @Id
    @GeneratedValue
    @JdbcTypeCode(SqlTypes.UUID)
    @Column(name = "schedule_identifier")
    private UUID scheduleIdentifier;

    @Column(name = "project_identifier", nullable = false)
    @JdbcTypeCode(SqlTypes.UUID)
    private UUID projectIdentifier;

    @Column(name = "product_identifier", nullable = true)
    @JdbcTypeCode(SqlTypes.UUID)
    private UUID productIdentifier;

    @Column(name = "account_id", nullable = false)
    @JdbcTypeCode(SqlTypes.UUID)
    private UUID accountId;

    @OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, orphanRemoval = true)
    @Builder.Default
    private List<ProjectScheduleTask> tasks = new ArrayList<>();

    @OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, orphanRemoval = true)
    @Builder.Default
    private List<ProjectScheduleDependency> dependencies = new ArrayList<>();

    @OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, orphanRemoval = true)
    @Builder.Default
    private List<ProjectScheduleGroup> groups = new ArrayList<>();
}
