package com.storlead.sales.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.storlead.framework.common.constant.CodeGenerateInterface;
import lombok.Data;
import lombok.Getter;

public enum ResourceTypeEnum {
    /**
     * 客户
     */
//    10:客户、11线索、20:联系人、30:商机、40:订单、50:回款、60:退款、70:费用、80:任务、90:跟进、100:工单
    CUSTOMER("10", "客户","customer","customer_name","customerName", CodeGenerateInterface.CUSTOMER_CODE),
    CLUS("11", "线索","customer","customer_name","customerName",CodeGenerateInterface.CUSTOMER_CODE),
    LIAISON("20", "联系人","liaison","name","name",CodeGenerateInterface.LIAISON_CODE),
    BUSINESS("30", "商机","business","title","title",CodeGenerateInterface.BUSINESS_CODE),
    ORDER_FORM("40", "订单","order_form","title","title",CodeGenerateInterface.ORDER_FORM_CODE),
//    TASK_CANCELED("50", "回款"),
//    TASK_CANCELED("60", "退款"),
//    TASK_CANCELED("70", "费用"),
    TASK_CANCELED("80", "任务","task","task_content","taskContent",CodeGenerateInterface.TASK_CODE),
    FOLLOW_UP("90", "跟进","customer_follow_up","content","content",""),
    WORK_ORDER("100", "工单","work_order","title","title",CodeGenerateInterface.WORK_ORDER_CODE),
    EMAIL("110", "邮件","email","subject","subject",CodeGenerateInterface.EMAIL_CODE),
    BULLETIN("120", "公告","bulletin","title","title",CodeGenerateInterface.BULLETIN_CODE),
    // 野鸡目标130
    ;
    /**
     * {@link EnumValue}标记数据库存的值是code
     */
    @EnumValue
    public String code;

    /**
     * {@link JsonValue} 标记json返回给前端显示的值是desc
     */
    @JsonValue
    public String desc;

    /**
     * {@link JsonValue} 标记json返回给前端显示的值是desc
     */
    @JsonValue
    public String tableName;

    @JsonValue
    public String columName;

    @JsonValue
    public String fieldName;

    @JsonValue
    public String codePrefix;

    ResourceTypeEnum(String code, String desc,String tableName,String columName,String fieldName,String codePrefix) {
        this.code = code;
        this.desc = desc;
        this.tableName = tableName;
        this.columName = columName;
        this.fieldName = fieldName;
        this.codePrefix = codePrefix;
    }

    public static String getCodeByValue(String value) {
        for (ResourceTypeEnum type : ResourceTypeEnum.values()) {
            if (type.tableName.equals(value)) {
                return type.code;
            }
        }
        return null;
    }

    public static String getDescByValue(String value) {
        for (ResourceTypeEnum type : ResourceTypeEnum.values()) {
            if (type.tableName.equals(value)) {
                return type.desc;
            }
        }
        return null;
    }

    public static String getFieldNameByValue(String value) {
        for (ResourceTypeEnum type : ResourceTypeEnum.values()) {
            if (type.tableName.equals(value)) {
                return type.fieldName;
            }
        }
        return null;
    }

    public static String getDescByCode(String code) {
        for (ResourceTypeEnum type : ResourceTypeEnum.values()) {
            if (type.code.equals(code)) {
                return type.desc;
            }
        }
        return null;
    }
    public static ResourceTypeEnum getTypeEnumByCode(String code) {
        for (ResourceTypeEnum type : ResourceTypeEnum.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(ResourceTypeEnum.getCodeByValue("CustomerEntity"));
    }
}
