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

import cn.reghao.jutil.jdk.web.db.BaseObject;
import cn.reghao.file.api.constant.UploadChannelType;
import cn.reghao.tnb.file.app.zoss.model.dto.UploadChannelDto;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

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

/**
 * @author reghao
 * @date 2024-02-23 15:05:30
 */
@NoArgsConstructor
@Getter
@Setter
public class UploadChannel extends BaseObject<Integer> {
    @NotNull
    private Integer userNodeId;
    @NotNull
    private Integer channelCode;
    @NotBlank
    private String name;
    @NotBlank
    private String prefix;
    @NotNull
    private Long maxSize;
    @NotNull
    private Integer fileType;
    @NotNull
    private Integer scope;
    @NotNull
    private Boolean setUrl;
    @NotNull
    private Boolean setCallback;
    @NotNull
    private Boolean enabled;
    @NotNull
    private Integer createBy;

    private String maxSizeStr;
    private String fileTypeStr;
    private String scopeStr;

    public UploadChannel(int channelCode, UploadChannelDto uploadChannelDto, int ossUser) {
        this.userNodeId = uploadChannelDto.getUserNodeId();
        this.channelCode = channelCode;
        this.name = uploadChannelDto.getChannelName();
        this.prefix = uploadChannelDto.getChannelPrefix();
        this.maxSize = uploadChannelDto.getMaxSize();
        this.fileType = uploadChannelDto.getObjectType();
        this.scope = uploadChannelDto.getScope();
        this.setUrl = false;
        this.setCallback = false;
        this.enabled = true;
        this.createBy = ossUser;
    }

    public UploadChannel(int userNodeId, UploadChannelType uploadChannelType, int ossUser) {
        this.userNodeId = userNodeId;
        this.channelCode = uploadChannelType.getChannelCode();
        this.name = uploadChannelType.name();
        this.prefix = uploadChannelType.getChannelPrefix();
        this.maxSize = uploadChannelType.getMaxSize();
        this.fileType = uploadChannelType.getFileType();
        this.scope = uploadChannelType.getScope();
        this.setUrl = false;
        this.setCallback = false;
        this.enabled = true;
        this.createBy = ossUser;
    }
}
