package com.ruoyi.ss.model.service.impl;

import com.ruoyi.common.core.domain.BaseValidator;
import com.ruoyi.ss.model.domain.SmModelVO;
import com.ruoyi.ss.model.domain.enums.ModelTag;
import com.ruoyi.ss.model.service.ModelService;
import com.ruoyi.ss.model.service.ModelValidator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 * 2024/4/22
 */
@Service
public class ModelValidatorImpl extends BaseValidator implements ModelValidator {

    @Autowired
    private ModelService modelService;

    @Override
    public boolean isRepeatModel(Long modelId, String model) {
        if (StringUtils.isBlank(model)) {
            return false;
        }
        SmModelVO repeat = modelService.selectByModel(model);
        return repeat != null && !Objects.equals(repeat.getModelId(), modelId);
    }

    /**
     * 判断标签是否合法
     */
    @Override
    public boolean hasTags(List<String> tags) {
        if (!CollectionUtils.isEmpty(tags)) {
            return ModelTag.contains(tags);
        }
        return true;
    }
}
