package cn.ysk.cashier.mybatis.service.impl;

import cn.ysk.cashier.enums.TableStateEnum;
import cn.ysk.cashier.mapper.shop.TbShopTableMapper;
import cn.ysk.cashier.mybatis.entity.TagProductDepts;
import cn.ysk.cashier.mybatis.mapper.MpShopTableMapper;
import cn.ysk.cashier.mybatis.mapper.TagProductDeptsMapper;
import cn.ysk.cashier.mybatis.service.MpShopTableService;
import cn.ysk.cashier.mybatis.service.TagProductDeptsService;
import cn.ysk.cashier.pojo.shop.TbShopTable;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class MpShopTableServiceImpl extends ServiceImpl<MpShopTableMapper, TbShopTable> implements MpShopTableService {

    @Override
    public boolean updateStateByTableId(TableStateEnum tableStateEnum, String tableId) {
        return update(new LambdaUpdateWrapper<TbShopTable>()
                .eq(TbShopTable::getQrcode, tableId)
                .set(TbShopTable::getStatus, tableStateEnum.getState()));
    }

    @Override
    public TbShopTable selectByStateAndTableId(TableStateEnum tableStateEnum, String tableId, Integer shopId) {
        return getOne(new LambdaQueryWrapper<TbShopTable>()
                .eq(TbShopTable::getShopId, shopId)
                .eq(TbShopTable::getStatus, tableStateEnum.getState())
                .eq(TbShopTable::getQrcode, tableId));
    }

    @Override
    public TbShopTable selectByTableId(String tableId, Integer shopId) {
        return getOne(new LambdaQueryWrapper<TbShopTable>()
                .eq(TbShopTable::getShopId, shopId)
                .eq(TbShopTable::getQrcode, tableId));
    }

    @Override
    public TbShopTable selectById(Integer id, Integer shopId) {
        return getOne(new LambdaQueryWrapper<TbShopTable>()
                .eq(TbShopTable::getId, id)
                .eq(TbShopTable::getShopId, shopId));
    }
}
