package com.smartoffice.leave;

import com.smartoffice.user.UserDto;

import java.time.Instant;

public record LeaveDto(
        Long id,
        UserDto requester,
        LeaveType type,
        Instant startTime,
        Instant endTime,
        String reason,
        LeaveStatus status,
        UserDto approver,
        Instant decidedAt,
        Instant createdAt
) {
    public static LeaveDto from(LeaveRequest request) {
        return new LeaveDto(
                request.getId(),
                UserDto.from(request.getUser()),
                request.getType(),
                request.getStartTime(),
                request.getEndTime(),
                request.getReason(),
                request.getStatus(),
                request.getApprover() == null ? null : UserDto.from(request.getApprover()),
                request.getDecidedAt(),
                request.getCreatedAt()
        );
    }
}
