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

import com.apobates.forum.event.elderly.ForumActionEnum;
import com.apobates.forum.utils.Commons;
import com.apobates.forum.utils.lang.EnumArchitecture;
import java.util.Optional;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Positive;
import javax.validation.constraints.Size;

/**
 *
 * @author xiaofanku
 * @since 20200603
 */
public class ForumScoreRoleForm extends ActionForm {
    //ForumActionEnum.symbol
    @NotBlank(message="{NotBlank.ForumScoreRoleForm.action}")
    @Size(min=0, max=110, message="{Size.ForumScoreRoleForm.action}")
    @Positive(message="{Positive.ForumScoreRoleForm.action}")
    private String action;
    //频次/int
    @NotBlank(message="{NotBlank.ForumScoreRoleForm.degree}")
    @Size(min=1, max=20, message="{Size.ForumScoreRoleForm.degree}")
    private String degree;
    //等级/int
    @NotBlank(message="{NotBlank.ForumScoreRoleForm.level}")
    @Positive(message="{Positive.ForumScoreRoleForm.level}")
    private String level;
    //得分/double
    @NotBlank(message="{NotBlank.ForumScoreRoleForm.score}")
    @DecimalMin(value="1", inclusive=true, message="{DecimalMin.ForumScoreRoleForm.score}")
    private String score;
    
    public Optional<ForumActionEnum> getEnumAction() {
        int d = covertStringToInteger(getAction(), -1);
        return EnumArchitecture.getInstance(d, ForumActionEnum.class);
    }
    
    public String getAction() {
        return action;
    }
    
    public void setAction(ForumActionEnum action) {
        setAction(action.getSymbol() + "");
    }
    
    public void setAction(String action) {
        this.action = action;
    }
    public int getIntegerDegree(){
        return Commons.stringToInteger(getDegree(), 1);
    }
    public String getDegree() {
        return degree;
    }
    
    public void setDegree(String degree) {
        this.degree = degree;
    }
    public int getIntegerLevel(){
        return Commons.stringToInteger(getLevel(), 1);
    }
    public String getLevel() {
        return level;
    }
    
    public void setLevel(String level) {
        this.level = level;
    }
    public double getDoubleScore(){
        return Commons.stringToDouble(()->getScore(), 1.0D);
    }
    public String getScore() {
        return score;
    }
    
    public void setScore(String score) {
        this.score = score;
    }
}