package com.example.volunteer.model;

import jakarta.persistence.*;
import java.time.LocalDate;

/**
 * ============================================================================
 * (a) 实体模型 / Entity model — Signup（报名记录）
 * ============================================================================
 *
 * 【为什么它必须是一个实体 / Why this must be an entity, not @ManyToMany】
 * EN — The sign-up carries its own data (signupDate, hours). A plain @ManyToMany join table
 *      can only hold the two foreign keys, so it cannot store these attributes.
 *      Adding attributes to either side would be wrong: hours belong to "this volunteer in
 *      this event", not to the volunteer or the event alone.
 * 中 — 报名记录带有自己的数据（报名日期、服务时数）。纯 @ManyToMany 生成的中间表只有两个外键，
 *      放不下这些字段；把 hours 放到 Event 或 Volunteer 上也都是错的，因为它属于
 *      "这个人在这个活动里的这一次报名"。
 *
 * 【关系 / Relationships】
 * EN — Two @ManyToOne: the owning side of both relationships; the foreign keys live here.
 * 中 — 两个 @ManyToOne：两段关系的拥有端，外键都在本表。
 *
 * 生成表 / Generated table:
 *   signup(id, event_id, volunteer_id, signup_date, hours)
 */
@Entity
public class Signup {

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

    @ManyToOne(optional = false)
    @JoinColumn(name = "event_id", nullable = false)
    private Event event;

    @ManyToOne(optional = false)
    @JoinColumn(name = "volunteer_id", nullable = false)
    private Volunteer volunteer;

    private LocalDate signupDate;
    private int hours;

    public Signup() { }

    public Signup(Volunteer volunteer, LocalDate signupDate, int hours) {
        this.volunteer = volunteer;
        this.signupDate = signupDate;
        this.hours = hours;
    }

    // ------------------------------------------------------------------ getters / setters

    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public Event getEvent() { return event; }
    public void setEvent(Event event) { this.event = event; }

    public Volunteer getVolunteer() { return volunteer; }
    public void setVolunteer(Volunteer volunteer) { this.volunteer = volunteer; }

    public LocalDate getSignupDate() { return signupDate; }
    public void setSignupDate(LocalDate signupDate) { this.signupDate = signupDate; }

    public int getHours() { return hours; }
    public void setHours(int hours) { this.hours = hours; }
}
