package cn.reghao.bnt.web.devops.app.model.dto;

import cn.reghao.bnt.web.devops.app.model.po.config.AppConfig;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import java.io.Serializable;

/**
 * @author reghao
 * @date 2021-06-03 16:15:23
 */
@Data
public class CopyAppDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @NotNull
    @Pattern(regexp = "^\\S*$", message = "应用 ID 不能包含空白符")
    @Length(min = 2, max = 10, message = "应用 ID 的最大长度为 20 个字符")
    private String appId;
    @NotNull
    @Pattern(regexp = "^\\S*$", message = "应用 ID 不能包含空白符")
    @Length(min = 2, max = 10, message = "应用 ID 的最大长度为 20 个字符")
    private String newAppId;
    @NotNull
    @NotBlank(message = "新应用环境不能为空白字符串")
    @Length(max = 20, message = "新应用环境最大长度为 10 个字符")
    private String newEnv;
    @NotNull
    @NotBlank(message = "新仓库分支不能为空白字符串")
    @Length(min = 1, max = 20, message = "新仓库分支最大长度为 40 个字符")
    private String newRepoBranch;

    public AppConfig app(AppConfig from) {
        from.setAppId(newAppId);
        from.setEnv(newEnv);
        from.setRepoBranch(newRepoBranch);

        from.setId(null);
        from.setCreateTime(null);
        from.setUpdateTime(null);
        return from;
    }
}
