package com.friday.tooldriver.dto.infodator.response;

import com.friday.operation.api.tooldriver.dto.rpa.CodePackageDto;
import com.friday.operation.api.tooldriver.dto.rpa.ReleaseDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Process implements Serializable {
    private Integer creatorId;
    private String updatorId;
    private String createTime;
    private String updateTime;
    private boolean deleted;
    private Integer version;
    private Integer id;
    private String templateId;
    private String name;
    private String description;
    private Integer itemExpectedTime;
    private Integer groupId;
    private boolean useFlag;
    private TemplateVersionDto templateVersion;

    public ReleaseDto createInfodatorReleaseDto(){
        return ReleaseDto.builder()
                .key(String.valueOf(this.getId()))
                .name(this.getName())
                .description(this.getDescription())
                .processVersion(this.getTemplateVersion() != null ? this.getTemplateVersion().getCode() : null)
                .latestVersion(true)
                .build();
    }

    public CodePackageDto createInfodatorCodePackageDto(){
        return CodePackageDto.builder()
                .key(this.getTemplateVersion() != null ? String.valueOf(this.getTemplateVersion().getId()) : null)
                .processKey(String.valueOf(this.getId()))
                .name(this.getName())
                .version(this.getTemplateVersion() != null ? this.getTemplateVersion().getCode() : null)
                .versionType(null)
                .fileType(null)
                .fileName(this.getTemplateVersion() != null ? this.getTemplateVersion().getName() : null)
                .build();
    }
}
