package ru.kirillius.pf.sdn.entity;

import jakarta.persistence.*;
import lombok.*;
import ru.kirillius.pf.sdn.api.flow.StartCondition;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "pipeline_config")
@Getter
@Setter
@NoArgsConstructor
@Builder
@AllArgsConstructor
public class FlowConfig {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, unique = true)
    private String name;

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof FlowConfig that)) return false;
        return Objects.equals(id, that.id) && Objects.equals(name, that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }

    @ManyToMany(fetch = FetchType.EAGER)
    private List<StartCondition> startConditions = new ArrayList<>();

    @ManyToMany(fetch = FetchType.EAGER)//TODO проверить связность
    private List<ActionConfig> actions = new ArrayList<>();

    @ManyToMany(fetch = FetchType.EAGER)//TODO проверить связность
    private List<ActionConnectionConfig> connections = new ArrayList<>();


}
