package cn.reghao.tnb.file.app.zoss.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.tnb.file.app.zoss.model.dto.NodeAddDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;

/**
 * @author reghao
 * @date 2024-02-27 09:45:11
 */
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class UserNode extends BaseObject<Integer> {
    @NotNull
    private Integer storeNodeId;
    @NotBlank
    @Pattern(regexp = "^[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,6}$", message = "域名格式不正确")
    private String domain;
    private String protocol;
    private String secretKey;
    private String referer;
    @NotNull
    private Integer createBy;

    private String storeNodeAddr;

    public UserNode(NodeAddDto nodeAddDto, int createBy) {
        this.storeNodeId = nodeAddDto.getStoreNodeId();
        this.domain = nodeAddDto.getDomain();
        this.protocol = nodeAddDto.getProtocol();
        this.createBy = createBy;
    }

    public UserNode(int storeNodeId, String domain, String secretKey, String referer, int createBy) {
        this.storeNodeId = storeNodeId;
        this.domain = domain;
        this.protocol = "http";
        this.secretKey = secretKey;
        this.referer = referer;
        this.createBy = createBy;
    }
}
