package com.fs.store.service.impl;

import java.util.Collections;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.fs.store.domain.FsWarehouses;
import com.fs.store.mapper.FsWarehousesMapper;
import com.fs.store.service.IFsWarehousesService;
import com.fs.system.cache.ISysDictDataCacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 仓库Service业务层处理
 *
 * @author fs
 * @date 2025-03-07
 */
@RequiredArgsConstructor
@Service
public class FsWarehousesServiceImpl implements IFsWarehousesService
{
    private final FsWarehousesMapper fsWarehousesMapper;
    private final ISysDictDataCacheService sysDictDataCacheService;

    /**
     * 查询仓库
     *
     * @param id 仓库ID
     * @return 仓库
     */
    @Override
    public FsWarehouses selectFsWarehousesById(Long id)
    {
        return fsWarehousesMapper.selectFsWarehousesById(id);
    }

    /**
     * 查询仓库列表
     *
     * @param fsWarehouses 仓库
     * @return 仓库
     */
    @Override
    public List<FsWarehouses> selectFsWarehousesList(FsWarehouses fsWarehouses)
    {
        List<FsWarehouses> warehouses = fsWarehousesMapper.selectFsWarehousesList(fsWarehouses);
        for (FsWarehouses warehouse : warehouses) {
            Integer isActive = warehouse.getIsActive();

            if(ObjectUtils.isEmpty(isActive)){
                isActive = 0;
            }
            String isActiveText = sysDictDataCacheService
                    .selectDictLabel("enable_options", String.valueOf(isActive));
            warehouse.setIsActiveText(isActiveText);
        }

        return warehouses;
    }

    /**
     * 新增仓库
     *
     * @param fsWarehouses 仓库
     * @return 结果
     */
    @Override
    public int insertFsWarehouses(FsWarehouses fsWarehouses)
    {
        return fsWarehousesMapper.insertFsWarehouses(fsWarehouses);
    }

    /**
     * 修改仓库
     *
     * @param fsWarehouses 仓库
     * @return 结果
     */
    @Override
    public int updateFsWarehouses(FsWarehouses fsWarehouses)
    {
        return fsWarehousesMapper.updateFsWarehouses(fsWarehouses);
    }

    /**
     * 批量删除仓库
     *
     * @param ids 需要删除的仓库ID
     * @return 结果
     */
    @Override
    public int deleteFsWarehousesByIds(List<Long> ids)
    {
        return fsWarehousesMapper.deleteFsWarehousesByIds(ids);
    }

    /**
     * 删除仓库信息
     *
     * @param id 仓库ID
     * @return 结果
     */
    @Override
    public int deleteFsWarehousesById(Long id)
    {
        return fsWarehousesMapper.deleteFsWarehousesById(id);
    }
}
