package com.example.volunteer.dto;

import jakarta.validation.constraints.*;

import java.time.LocalDate;

/**
 * ============================================================================
 * 表单对象（form-backing object）— 对应样卷 Q4(e) / Q5(a)
 * ============================================================================
 *
 * 【题目 / Question (sample Q4e + Q5a)】
 * EN — (e) Complete the essential HTML tags for the item form (name, price, category).
 *      (a) Is validation necessary? Which Spring components are most suitable? Justify.
 * 中 — (e) 补全新增表单的关键 HTML 标签；(a) 校验是否必要？哪些 Spring 组件最合适？说明理由。
 *
 * 【为什么用单独的 DTO，而不是直接绑定实体 / Why a DTO】
 * EN — The form only exposes a subset of fields, and validation rules belong to the input,
 *      not to the persisted model. A DTO keeps the entity clean and is the "form-backing
 *      object" that Bean Validation annotations attach to.
 * 中 — 表单只暴露部分字段；校验规则属于“输入”，不属于持久化模型。用 DTO 可以让实体保持干净，
 *      它也正是 Bean Validation 注解所依附的 “form-backing object”。
 *
 * 【校验分两层 / Two layers of validation】
 * EN — ① field-level: annotations here (@NotBlank / @Min / @FutureOrPresent)
 *      ② business-level: rules that need other data (e.g. "no two events in the same venue
 *         on the same day") must live in the Service, not here.
 * 中 — ① 字段级：本类的注解（@NotBlank / @Min / @FutureOrPresent）
 *      ② 业务级：需要查其他数据的规则（如“同一场地同一天不能有两场活动”）必须放在 Service。
 */
public class EventForm {

    @NotBlank(message = "Title is required")
    @Size(max = 100, message = "Title must be at most 100 characters")
    private String title;

    @NotNull(message = "Event date is required")
    @FutureOrPresent(message = "Event date cannot be in the past")
    private LocalDate eventDate;

    @NotBlank(message = "Location is required")
    private String location;

    @Min(value = 1, message = "Capacity must be at least 1")
    @Max(value = 500, message = "Capacity must be at most 500")
    private int capacity;

    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }

    public LocalDate getEventDate() { return eventDate; }
    public void setEventDate(LocalDate eventDate) { this.eventDate = eventDate; }

    public String getLocation() { return location; }
    public void setLocation(String location) { this.location = location; }

    public int getCapacity() { return capacity; }
    public void setCapacity(int capacity) { this.capacity = capacity; }
}
