package com.ga.core.vo.upload;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.List;

/**
 * 업로드 템플릿 등록/수정 요청.
 */
@Data
public class UploadTemplateSaveReq {

    @NotBlank
    private String templateCode;

    @NotBlank
    private String templateName;

    private String category;

    @NotBlank
    private String targetTable;

    private String companyCode;
    private Integer headerRow;
    private Integer dataStartRow;
    private Integer sheetIndex;
    private String sheetName;
    private String fileEncoding;
    private String delimiter;
    private String skipEmptyRow;
    private Integer maxErrorCount;
    private Integer batchSize;
    private String description;
    private String isActive;

    @Valid
    private List<UploadTemplateColumnVO> columns;

    public UploadTemplateVO toVO() {
        UploadTemplateVO vo = new UploadTemplateVO();
        vo.setTemplateCode(this.templateCode);
        vo.setTemplateName(this.templateName);
        vo.setCategory(this.category);
        vo.setTargetTable(this.targetTable);
        vo.setCompanyCode(this.companyCode);
        vo.setHeaderRow(this.headerRow != null ? this.headerRow : 1);
        vo.setDataStartRow(this.dataStartRow != null ? this.dataStartRow : 2);
        vo.setSheetIndex(this.sheetIndex != null ? this.sheetIndex : 0);
        vo.setSheetName(this.sheetName);
        vo.setFileEncoding(this.fileEncoding != null ? this.fileEncoding : "UTF-8");
        vo.setDelimiter(this.delimiter);
        vo.setSkipEmptyRow(this.skipEmptyRow != null ? this.skipEmptyRow : "Y");
        vo.setMaxErrorCount(this.maxErrorCount != null ? this.maxErrorCount : 100);
        vo.setBatchSize(this.batchSize != null ? this.batchSize : 1000);
        vo.setDescription(this.description);
        vo.setIsActive(this.isActive != null ? this.isActive : "Y");
        return vo;
    }
}
