package com.chushang.inspection.work.query;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DatePattern;
import com.chushang.common.core.text.Convert;
import com.chushang.common.dict.utils.DictUtils;
import com.chushang.common.mybatis.page.CommonParam;
import com.chushang.inspection.work.enums.WorkTypeOperation;
import com.chushang.inspection.work.po.WrkIcbcJs;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DispatchQuery extends CommonParam {

//    @NotNull(message = "终端id 不能为空")
    /** 终端id */
    private List<Long> terminalIds;


    @NotNull(message = "分配业务员不能为空")
    /** 业务员id */
    private Long userId;

    /** 工单类型 */
    @NotNull(message = "必须指定工单类型")
    @Range(min = 1, max = 50, message = "工单类型非法")
    private Integer workType;

    /** 截至时间 */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN)
    private LocalDateTime endTime;

    /** 工单优先级 */
    @Builder.Default
    private Integer workSort = Convert.toInt(DictUtils.getDictLabel("wrk_priority", "普通工单"));

    /** 备注 */
    @Size(max = 100, message = "备注不能超过100个字符")
    private String remark;

    /** 工单来源 */
    @Range(min = 1, max = 4, message = "工单来源非法")
    private Integer workSource;


    public DispatchQuery dispatchOrder(WrkIcbcJs entity, Long userId) {
        this.terminalIds = ListUtil.toList(entity.getTerminalId());
        this.userId = userId;
        this.workType = WorkTypeOperation.valueOfCode(entity.getOrderType());
        this.remark = entity.getNoteMsg();
        this.workSource = 1;
        return this;
    }

    private List<String> terminalNos = new ArrayList<>();
}
