package com.iqser.red.service.persistence.service.v1.api.shared.model.license;

import java.time.Instant;
import java.time.Year;
import java.time.ZoneOffset;

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

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class LicenseReportRequest {

    private Instant startDate;
    private Instant endDate;

    public Instant getStartDate() {

        if (startDate == null) {
            startDate = Year.of(getEndDate().atOffset(ZoneOffset.UTC).getYear()).atMonth(1).atDay(1).atStartOfDay().toInstant(ZoneOffset.UTC);
        }
        return startDate;
    }


    public Instant getEndDate() {

        if (endDate == null || endDate.isAfter(Instant.now())) {
            endDate = Instant.now();
        }
        return endDate;
    }

}
