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

import com.apobates.forum.core.entity.ForumEntityStatusEnum;
import com.apobates.forum.utils.lang.EnumArchitecture;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Positive;
import javax.validation.constraints.Size;

/**
 * 子栏目(原生版块)的表单
 * @author xiaofanku
 * @since 20200603
 */
public class SectionTermForm extends ActionForm {
    @NotBlank(message="{NotBlank.SectionTermForm.title}")
    private String title;
    @NotBlank(message="{NotBlank.SectionTermForm.direct}")
    @Size(min=4, max=19, message="{Size.SectionTermForm.direct}")
    @Pattern(regexp = "^[A-Za-z0-9]+$", message="{Pattern.SectionTermForm.direct}")
    private String direct;
    @NotBlank(message="{NotBlank.SectionTermForm.description}")
    private String description;
    //int|boardGroupId
    @NotBlank(message="{NotBlank.SectionTermForm.section}")
    @Positive(message="{Positive.SectionTermForm.section}")
    private String section;
    //ForumEntityStatusEnum
    @NotBlank(message="{NotBlank.SectionTermForm.entityStatus}")
    @Min(value=0, message="{Min.SectionTermForm.entityStatus}")
    @Max(value=4, message="{Max.SectionTermForm.entityStatus}")
    private String entityStatus = "4";
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getDirect() {
        return direct;
    }
    
    public void setDirect(String direct) {
        this.direct = direct;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public int getIntegerSection() {
        return covertStringToInteger(getSection(), 0);
    }
    
    public String getSection() {
        return section;
    }
    
    public void setSection(String section) {
        this.section = section;
    }
    
    public ForumEntityStatusEnum getEnumEntityStatus() {
        int d = covertStringToInteger(getEntityStatus(), 4);
        return EnumArchitecture.getInstance(d, ForumEntityStatusEnum.class).orElse(ForumEntityStatusEnum.ACTIVE);
    }
    
    public String getEntityStatus() {
        return entityStatus;
    }
    
    public void setEntityStatus(String entityStatus) {
        this.entityStatus = entityStatus;
    }
    
    public void setEntityStatus(ForumEntityStatusEnum status) {
        setEntityStatus(status.getSymbol() + "");
    }
}