package cn.axzo.msg.center.service.pending.request;

import cn.axzo.basics.common.page.PageRequest;
import cn.axzo.maokai.common.enums.OrgUserStatusEnum;
import cn.axzo.msg.center.service.enums.AppTerminalTypeEnum;
import cn.axzo.msg.center.service.enums.BizCategoryEnum;
import cn.axzo.msg.center.service.enums.PendingMessageStateEnum;
import cn.axzo.msg.center.service.enums.TerminalTypeEnum;
import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GetTodoPageRequest extends PageRequest {
    private TerminalTypeEnum terminalType;
    private AppTerminalTypeEnum appTerminalType;
    private String titleLike;
    private BizCategoryEnum bizCategory;
    private Set<String> identityCodes;
    private Set<String> templateCodes;
    private Set<String> bizCodes;
    private Set<PendingMessageStateEnum> states;
    private List<GetTodoPageRequest.Executor> executors;
    /**
     * 代办消息的分类结点编码, 单个节点. groupNodeCodes的优先级高于groupNodeCode
     */
    private String groupNodeCode;
    /**
     * 代办消息的分类结点编码, 支持多个节点. groupNodeCodes的优先级高于groupNodeCode
     */
    private Collection<String> groupNodeCodes;

    @NotNull
    public Collection<String> determineGroupNodeCodes() {
        if (CollectionUtils.isNotEmpty(groupNodeCodes)) {
            return groupNodeCodes;
        }
        if (StringUtils.isNotBlank(groupNodeCode)) {
            return Collections.singletonList(groupNodeCode);
        }
        return Collections.emptyList();
    }

    @Setter
    @Getter
    public static class Executor {
        private Long ouId;
        private Long workspaceId;
        private List<Long> personIds;
    }

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