package com.bonus.canteen.core.menu.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.menu.dto.DrpUnitPageDTO;
import com.bonus.canteen.core.menu.dto.MenuDishesTypeAddDTO;
import com.bonus.canteen.core.menu.dto.MenuDishesTypeEditDTO;
import com.bonus.canteen.core.menu.enums.MgrRoleTypeV2Enum;
import com.bonus.canteen.core.menu.enums.RoleCodeV2Enum;
import com.bonus.canteen.core.menu.mapper.MenuDishesTypeMapper;
import com.bonus.canteen.core.menu.service.MenuDishesTypeService;
import com.bonus.canteen.core.menu.domain.MenuDishesType;
import com.bonus.canteen.core.menu.vo.DrpUnitPageVO;
import com.bonus.canteen.core.menu.vo.MenuDishesTypeAllVO;
import com.bonus.canteen.core.utils.BnsConstants;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.houqin.constant.DelFlagEnum;
import com.bonus.common.houqin.i18n.I18n;
import com.bonus.common.houqin.utils.id.Id;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.system.api.model.LoginUser;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

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

/**
 * @author xliu
 * @date 2025/4/8 19:16
 */
@Service
public class MenuDishesTypeServiceImpl  extends ServiceImpl<MenuDishesTypeMapper, MenuDishesType> implements MenuDishesTypeService {

    @Resource
    private MenuDishesTypeMapper menuDishesTypeMapper;

    @Override
    public List<MenuDishesTypeAllVO> getAllMenuDishesTypeList() {
        return menuDishesTypeMapper.getAllMenuDishesTypeList();
    }


    @Override
    public int addMenuDishesType(MenuDishesTypeAddDTO content) {
        List<MenuDishesType> cookList = this.baseMapper.selectList(Wrappers.lambdaQuery(MenuDishesType.class)
                .eq(MenuDishesType::getTypeName, content.getTypeName())
                .eq(MenuDishesType::getDelFlag, DelFlagEnum.DEL_FALSE.key()));
        if (CollUtil.isNotEmpty(cookList)) {
            throw new ServiceException("菜品已存在");
        } else {
            String username = SecurityUtils.getUsername();
            MenuDishesType dishesType = new MenuDishesType();
            BeanUtil.copyProperties(content, dishesType, new String[0]);
            dishesType.setCreateBy(username);
            dishesType.setTypeId(Id.next());
            return this.baseMapper.insert(dishesType);
        }
    }

    @Override
    public List<DrpUnitPageVO> getDrpUnitPage(DrpUnitPageDTO dto) {
      //  dto.setAreaAuth(getTenantAreaIdList(BnsConstants.COMMON_YES));
        return menuDishesTypeMapper.selectAllList(dto);
    }

    @Override
    public int updateMenuDishesType(MenuDishesTypeEditDTO content) {
        return menuDishesTypeMapper.updateMenuDishesType(content);
    }

    @Override
    public int delMenuDishesType(MenuDishesTypeEditDTO content) {

        return  menuDishesTypeMapper.delMenuDishesType(content);
    }
}
