package com.example.volunteer.service;

import com.example.volunteer.model.Signup;

import java.time.LocalDate;

/**
 * ============================================================================
 * 查询结果投影 — 样卷 Q4(c)
 * ============================================================================
 *
 * EN — Returned instead of the entity so that the controller does not touch lazy
 *      associations after the transaction has ended.
 * 中 — 返回投影而不是实体，避免 Controller 在事务结束后访问惰性关联。
 */
public record SignupView(Long id,
                         Long eventId,
                         String eventTitle,
                         String volunteerName,
                         LocalDate signupDate,
                         int hours) {

    public static SignupView from(Signup s) {
        return new SignupView(
                s.getId(),
                s.getEvent().getId(),
                s.getEvent().getTitle(),
                s.getVolunteer().getName(),
                s.getSignupDate(),
                s.getHours());
    }
}
