package relations.tworelations;

import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * ============================================================================
 * 关系情形 ⑥：同一对实体的两条关联 —— Department（反向端）
 * ============================================================================
 *
 * 【关系 / Relationship】
 * EN — Two inverse sides, one per relationship. The mappedBy values must match the two field
 *      names in Doctor ("headed" and "joined") exactly.
 * 中 — 两个反向端，每段关系一个。mappedBy 的值必须与 Doctor 里两个字段名
 *      （"headed" 与 "joined"）完全一致。
 *
 * 【设计建议 / Design tip】
 * EN — Give the two fields meaningful names (headed / joined) instead of dept1 / dept2;
 *      the name is what a reader uses to tell the two associations apart.
 * 中 — 两个字段要有语义名字（headed / joined），不要叫 dept1 / dept2；
 *      读代码的人正是靠字段名区分这两段关联。
 */
@Entity
public class Department {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;

    @OneToMany(mappedBy = "headed")
    private List<Doctor> heads = new ArrayList<>();

    @OneToMany(mappedBy = "joined")
    private List<Doctor> members = new ArrayList<>();

    public Department() { }
    public Department(String name) { this.name = name; }

    public Long getId() { return id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public List<Doctor> getHeads() { return heads; }
    public List<Doctor> getMembers() { return members; }
}
