/*!
Copyright (c) REBUILD <https://getrebuild.com/> and/or its owners. All rights reserved.

rebuild is dual-licensed under commercial and open source licenses (GPLv3).
See LICENSE and COMMERCIAL in the project root for license information.
*/

package com.rebuild.core.metadata.easymeta;

import cn.devezhao.persist4j.Field;
import org.springframework.util.Assert;

import java.util.regex.Pattern;

/**
 * 签名。png,base64 格式
 *
 * @author devezhao
 * @since 2021/12/30
 */
public class EasySign extends EasyField implements PatternValue {
    private static final long serialVersionUID = -1748773030681695060L;

    protected EasySign(Field field, DisplayType displayType) {
        super(field, displayType);
    }
    
    @Override
    public Object convertCompatibleValue(Object value, EasyField targetField) {
        Assert.isTrue(targetField.getDisplayType() == getDisplayType(),
                "TYPE-BY-TYPE IS MUST (" + this.getName() + ">" + targetField.getName() + ")");
        return value;
    }

    @Override
    public Pattern getPattern() {
        return null;
    }

    @Override
    public boolean checkPattern(String value) {
        if (value == null) return true;
        return value.startsWith("data:image/png;base64,");
    }
}
