package com.ssj.enums;

import java.util.Objects;

/**
 * @author yrf
 * @date 2019/7/17 15:21
 */
public enum CompositionTypeEnum {

    PictureWriting(1, "看图写话"),
    TopicWriting(2, "话题写话");

    private int code;
    private String description;

    CompositionTypeEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static String getDescriptionByCode(int code) {
        for (CompositionTypeEnum compositionTypeEnum : CompositionTypeEnum.values()) {
            if (Objects.equals(code, compositionTypeEnum.getCode())) {
                return compositionTypeEnum.getDescription();
            }
        }

        return null;
    }

    public static int getCodeByDescription(String description) {
        for (CompositionTypeEnum compositionTypeEnum : CompositionTypeEnum.values()) {
            if (Objects.equals(description, compositionTypeEnum.getDescription())) {
                return compositionTypeEnum.getCode();
            }
        }
        return -1;
    }
}
