package com.keyware.shandan.mark.services;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.keyware.shandan.system.constants.FormTypeEnum;
import com.keyware.shandan.mark.pojo.FormMark;
import com.keyware.shandan.mark.pojo.MarkRecord;
import com.keyware.shandan.mark.pojo.MarkType;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * @author GuoXin
 * @date 2022-05-20
 */
@Service
public class MarkService {
    private final MarkTypeService typeService;
    private final MarkFormService formService;
    private final MarkRecordService recordService;

    public MarkService(MarkTypeService typeService, MarkFormService formService, MarkRecordService recordService) {
        this.typeService = typeService;
        this.formService = formService;
        this.recordService = recordService;
    }

    /**
     * 获取指定类型表单的标签类型配置
     * @param formType 表单类型
     * @return 标签类型配置
     */
    public List<FormMark> getConfigByFormType(FormTypeEnum formType) {
        QueryWrapper<FormMark> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("FORM_TYPE", formType.name());
        return formService.list(queryWrapper);
    }

    public List<MarkRecord> getValuesByEntity(String entityId){
        QueryWrapper<MarkRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ENTITY_ID", entityId);
        return recordService.list(queryWrapper);
    }

    public boolean hasMarks(Serializable entityId){
        QueryWrapper<MarkRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ENTITY_ID", entityId);
        return recordService.count(queryWrapper) > 0;
    }

    public MarkType getMarkType(Serializable markTypeId) {
        return typeService.getById(markTypeId);
    }
}
