package com.njzscloud.common.sn.support;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import com.njzscloud.common.core.ex.Exceptions;
import com.njzscloud.common.sn.contant.SnSection;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Map;

@Getter
@Setter
@Accessors(chain = true)
public class FixedSectionConfig implements SectionConfig {
    private final SnSection sectionName = SnSection.GuDing;
    /**
     * 固定值
     */
    private String value;


    @Override
    public String genExample() {
        return value;
    }

    @Override
    public ISnSection section() {
        return new FixedSection(value);
    }

    @Override
    public void resolve(Map<String, Object> config) {
        value = MapUtil.getStr(config, "value");
        Assert.notBlank(value, () -> Exceptions.clierr("固定编码配置错误，未设置字段 value"));
    }
}
