package com.apobates.forum.thrones.admin.controller.form;

import com.apobates.forum.core.ImageIOMeta;
import com.apobates.forum.utils.Commons;

import java.util.Optional;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;

/**
 *
 * @author xiaofanku
 * @since 20200603
 */
public class MemberLevelForm extends ActionForm {
    /**
     * 等级名称
     */
    @NotBlank(message="{NotBlank.MemberLevelForm.names}")
    private String names;
    /**
     * 最少积分/double
     */
    @NotBlank(message="{NotBlank.MemberLevelForm.minScore}")
    @DecimalMin(value="1", inclusive=true, message="{DecimalMin.MemberLevelForm.minScore}")
    private String minScore;
    /**
     * 上限积分/double
     */
    @NotBlank(message="{NotBlank.MemberLevelForm.score}")
    @DecimalMin(value="1", inclusive=false, message="{DecimalMin.MemberLevelForm.score}")
    private String score;
    /**
     * 等级图标
     */
    private String imageAddr;
    //上传后的图片地址
    private String fileurl;
    
    public String getNames() {
        return names;
    }
    
    public void setNames(String names) {
        if(null != names && names.equalsIgnoreCase("NUL")){
            this.names = "";
            return;
        }
        this.names = names;
    }
    public double getDoubleMinScore(){
        return Commons.stringToDouble(()->getMinScore(), 1.0D);
    }
    public String getMinScore() {
        return minScore;
    }
    
    public void setMinScore(String minScore) {
        this.minScore = minScore;
    }
    public double getDoubleScore(){
        return Commons.stringToDouble(()->getScore(), 1.0D);
    }
    public String getScore() {
        return score;
    }
    
    public void setScore(String score) {
        this.score = score;
    }
    
    public String getImageAddr() {
        return imageAddr;
    }
    
    public void setImageAddr(String imageAddr) {
        this.imageAddr = imageAddr;
    }
    
    public String getFileurl() {
        return fileurl;
    }
    
    public void setFileurl(String fileurl) {
        this.fileurl = fileurl;
    }
    public Optional<String> getEncodeIcoAddr(ImageIOMeta imageIOMeta){
        return encodeUploadImageURL(imageIOMeta, getFileurl());
    }
}