package com.qqchen.deploy.backend.framework.query;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DateRange {

    private LocalDateTime from;

    private LocalDateTime to;

    public boolean hasFrom() {
        return from != null;
    }

    public boolean hasTo() {
        return to != null;
    }

    public boolean isValid() {
        return from != null && to != null && !from.isAfter(to);
    }

    // 便捷方法
    public static DateRange of(LocalDateTime from, LocalDateTime to) {
        return new DateRange(from, to);
    }

    public static DateRange lastDays(int days) {
        return new DateRange(
            LocalDateTime.now().minusDays(days),
            LocalDateTime.now()
        );
    }

    public static DateRange today() {
        LocalDateTime now = LocalDateTime.now();
        return new DateRange(
            now.withHour(0).withMinute(0).withSecond(0),
            now.withHour(23).withMinute(59).withSecond(59)
        );
    }
}