package com.cool.store.dao.visit;

import com.cool.store.entity.visit.StoreVisitReservationDO;
import com.cool.store.mapper.visit.StoreVisitReservationMapper;
import com.cool.store.request.visit.StoreVisitReservationAdminQueryRequest;
import com.cool.store.vo.visit.StoreVisitReservationVO;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class StoreVisitReservationDAO {

    private final StoreVisitReservationMapper storeVisitReservationMapper;

    public Boolean insertSelective(StoreVisitReservationDO reservationDO) {
        return storeVisitReservationMapper.insertSelective(reservationDO) > 0;
    }

    public Boolean updateSelective(StoreVisitReservationDO reservationDO) {
        return storeVisitReservationMapper.updateByPrimaryKeySelective(reservationDO) > 0;
    }

    public StoreVisitReservationDO getById(Long id) {
        return storeVisitReservationMapper.selectByPrimaryKey(id);
    }

    public List<StoreVisitReservationDO> listByMobile(String mobile,Integer status) {
        Example example = new Example(StoreVisitReservationDO.class);
        Example.Criteria criteria = example.createCriteria()
                .andEqualTo("deleted", 0);
        if (StringUtils.isNotBlank(mobile)) {
            criteria.andEqualTo("mobile", mobile);
        }
        if (status!=null){
            criteria.andEqualTo("status",status);
        }
        example.setOrderByClause("create_time DESC");
        return storeVisitReservationMapper.selectByExample(example);
    }

    public List<StoreVisitReservationVO> adminPage(StoreVisitReservationAdminQueryRequest request) {
        return storeVisitReservationMapper.adminPage(request);
    }
}
