package cn.axzo.msg.center.notices.manager.api.dto.request.plat;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.joda.time.DateTime;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * @author yanglin
 */
@Data
public class TingyunInterfaceListRequest {

    @NotBlank
    private String auth;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date startDate;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date endDate;
    private Long bizSystemId = 4449L;
    @NotEmpty
    private List<ActionInfo> actions;

    public Date determineStartDate() {
        if (startDate != null)
            return startDate;
        return new DateTime(determineEndDate()).minusDays(60).toDate();
    }

    public Date determineEndDate() {
        if (endDate != null)
            return endDate;
        return new Date();
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    @Data
    public static class ActionInfo {
        @NotNull
        private Long applicationId;
        @NotBlank
        private String actionName;
    }

}