package test.model;

import model.ApprovalStatus;
import model.LeaveRequest;
import model.Student;
import model.Teacher;
import org.junit.Test;
import java.util.Date;
import static org.junit.Assert.*;

public class LeaveRequestTest {
    
    @Test
    public void testDefaultConstructor() {
        LeaveRequest request = new LeaveRequest();
        
        assertEquals("新建请假申请应为待审批状态", ApprovalStatus.PENDING, request.getStatus());
        assertNotNull("申请时间不应为空", request.getRequestTime());
    }
    
    @Test
    public void testSettersAndGetters() {
        LeaveRequest request = new LeaveRequest();
        
        // 设置测试数据
        int id = 1;
        Student student = new Student();
        student.setId(1);
        student.setName("张三");
        
        Teacher approver = new Teacher();
        approver.setId(1);
        approver.setName("李老师");
        
        Date startTime = new Date();
        Date endTime = new Date(startTime.getTime() + 86400000); // 一天后
        double duration = 24.0;
        String location = "北京";
        String reasonType = "事假";
        String reasonDetail = "参加比赛";
        String approvalComment = "同意";
        Date approvalTime = new Date();
        
        // 设置属性
        request.setId(id);
        request.setStudent(student);
        request.setStartTime(startTime);
        request.setEndTime(endTime);
        request.setDuration(duration);
        request.setLocation(location);
        request.setReasonType(reasonType);
        request.setReasonDetail(reasonDetail);
        request.setLeavingCity(true);
        request.setStatus(ApprovalStatus.APPROVED);
        request.setApprover(approver);
        request.setApprovalComment(approvalComment);
        request.setApprovalTime(approvalTime);
        
        // 验证
        assertEquals("ID应匹配", id, request.getId());
        assertEquals("学生信息应匹配", student, request.getStudent());
        assertEquals("开始时间应匹配", startTime, request.getStartTime());
        assertEquals("结束时间应匹配", endTime, request.getEndTime());
        assertEquals("时长应匹配", duration, request.getDuration(), 0.01);
        assertEquals("地点应匹配", location, request.getLocation());
        assertEquals("请假类型应匹配", reasonType, request.getReasonType());
        assertEquals("请假原因应匹配", reasonDetail, request.getReasonDetail());
        assertTrue("是否离津应匹配", request.isLeavingCity());
        assertEquals("状态应匹配", ApprovalStatus.APPROVED, request.getStatus());
        assertEquals("审批人应匹配", approver, request.getApprover());
        assertEquals("审批意见应匹配", approvalComment, request.getApprovalComment());
        assertEquals("审批时间应匹配", approvalTime, request.getApprovalTime());
    }
}
