package com.docus.server.archivefile.convert;

import com.docus.infrastructure.web.response.PageResult;
import com.docus.server.entity.TaskMessage;
import com.docus.server.enums.CollectTypeEnum;
import com.docus.server.enums.StateEnum;
import com.docus.server.vo.archivefile.TaskMessageVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface TaskMessageConvert {

    TaskMessageConvert INSTANCE = Mappers.getMapper(TaskMessageConvert.class);

    @Mappings({})
    TaskMessageVO convert(TaskMessage taskMessage);

    @Mappings({})
    List<TaskMessageVO> convert(List<TaskMessage> taskMessages);

    @Mappings({})
    PageResult<TaskMessageVO> convert(PageResult<TaskMessage> pageResult);

    default TaskMessage convert(String json, String xml, CollectTypeEnum collectType, String retryKey, Long id) {
        TaskMessage taskOriginalMessage = new TaskMessage();
        taskOriginalMessage.setId(id);
        taskOriginalMessage.setName(collectType.getDesc());
        taskOriginalMessage.setMemo(collectType.getDisplay());
        taskOriginalMessage.setCollectType(collectType);
        taskOriginalMessage.setRetryKey(retryKey);
        taskOriginalMessage.setJsonStr(json);
        taskOriginalMessage.setSource(xml);
        taskOriginalMessage.setState(StateEnum.OK);
        return taskOriginalMessage;
    }
}
