package relations.one2one;

import jakarta.persistence.*;

/**
 * ============================================================================
 * 关系情形 ④：一对一 1:1 —— Desk（反向端）
 * ============================================================================
 *
 * 【关系 / Relationship】
 * EN — The inverse side uses @OneToOne(mappedBy = "desk"). It has no foreign key column of
 *      its own; the column lives on the employee table.
 * 中 — 反向端用 @OneToOne(mappedBy = "desk")，它本身没有外键列，外键在 employee 表上。
 *
 * 【易错点 / Pitfall】
 * EN — Two @OneToOne sides without mappedBy produce two foreign key columns in two tables
 *      (a bidirectional 1:1 mapped twice), which is legal but almost never what you want.
 * 中 — 两端都写 @JoinColumn 会在两张表上各生成一个外键（同一段关系被映射两次），
 *      语法允许，但基本不是你要的。
 */
@Entity
public class Desk {

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

    private String floor;
    private String zone;

    @OneToOne(mappedBy = "desk")
    private Employee employee;

    public Desk() { }
    public Desk(String floor, String zone) { this.floor = floor; this.zone = zone; }

    public Long getId() { return id; }
    public String getFloor() { return floor; }
    public void setFloor(String floor) { this.floor = floor; }
    public String getZone() { return zone; }
    public void setZone(String zone) { this.zone = zone; }
    public Employee getEmployee() { return employee; }
}
