package com.zjt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.zjt.entity.ProductionVariety;
import com.zjt.mapper.ProductionVarietyMapper;
import com.zjt.service.IProductionVarietyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xxu
 * @since 2025-09-25
 */
@Service
public class ProductionVarietyServiceImpl extends ServiceImpl<ProductionVarietyMapper, ProductionVariety> implements IProductionVarietyService {

    private static final Logger logger = LoggerFactory.getLogger(ProductionVarietyServiceImpl.class);
    @Resource
    ProductionVarietyMapper ProductionVarietyMapper;

    @Override
    public String VarietyList(String materialTypeCode) {
        return "";
    }

    @Override
    public List<ProductionVariety> varietyList() {
        try {
            List<ProductionVariety> productionVarieties = ProductionVarietyMapper.selectVariety();
            return productionVarieties;
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }


    @Override
    public String updateVariety(String materialTypeCode) {
        if (!validateMaterialTypeCode(materialTypeCode, "更新品种")) {
            return "";
        }
        try {
            // TODO: 实现具体的业务逻辑
            logger.info("更新品种，materialTypeCode: {}", materialTypeCode);
            return "";
        } catch (Exception e) {
            logger.error("更新品种异常，materialTypeCode: {}", materialTypeCode, e);
            return "";
        }
    }

    @Override
    public String deleteVariety(String materialTypeCode) {
        if (!validateMaterialTypeCode(materialTypeCode, "删除品种")) {
            return "";
        }
        try {
            // TODO: 实现具体的业务逻辑
            logger.info("删除品种，materialTypeCode: {}", materialTypeCode);
            return "";
        } catch (Exception e) {
            logger.error("删除品种异常，materialTypeCode: {}", materialTypeCode, e);
            return "";
        }
    }

    private boolean validateMaterialTypeCode(String materialTypeCode, String operation) {
        if (StringUtils.isBlank(materialTypeCode)) {
            logger.warn("{}时materialTypeCode参数为空", operation);
            return false;
        }
        return true;
    }
}
