package com.lanyuanxiaoyao.server.entity;

import com.lanyuanxiaoyao.server.configuration.Constants;
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
import com.yahoo.elide.annotation.Include;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.Set;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 组织
 *
 * @author lanyuanxiaoyao
 * @version 20250327
 */
@Getter
@Setter
@ToString
@Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "department")
@Include
public class Department {
  @Id
  @SnowflakeId.Generator
  private Long departmentId;
  private String departmentName;

  @ManyToOne(optional = false)
  @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
  private Organization organization;

  @OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
  @ToString.Exclude
  private Set<User> users;

  @ManyToOne
  private Department parent;
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
  @ToString.Exclude
  private Set<Department> children;
}
