package com.jeesharp.business.modules.food.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jeesharp.business.modules.food.entity.FoodCompanyJoinApply;
import com.jeesharp.business.modules.food.mapper.FoodCompanyJoinApplyMapper;
import com.jeesharp.business.modules.food.service.FoodCompanyJoinApplyService;
import com.jeesharp.business.modules.food.vo.FoodCompanyJoinApplyQueryVO;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class FoodCompanyJoinApplyServiceImpl extends CrudService<FoodCompanyJoinApplyMapper, FoodCompanyJoinApply, FoodCompanyJoinApplyQueryVO> implements FoodCompanyJoinApplyService {

    private static final String DEL_NORMAL = "0";
    private static final String STATUS_PENDING = "pending";

    @Override
    public FoodCompanyJoinApply getPendingApply(String companyId, String memberId) {
        return getBaseMapper().selectOne(new LambdaQueryWrapper<FoodCompanyJoinApply>()
            .eq(FoodCompanyJoinApply::getCompanyId, companyId)
            .eq(FoodCompanyJoinApply::getMemberId, memberId)
            .eq(FoodCompanyJoinApply::getStatus, STATUS_PENDING)
            .eq(FoodCompanyJoinApply::getDelFlag, DEL_NORMAL)
            .last("limit 1"));
    }

    @Override
    public List<FoodCompanyJoinApply> listByMemberId(String memberId) {
        return getBaseMapper().selectList(new LambdaQueryWrapper<FoodCompanyJoinApply>()
            .eq(FoodCompanyJoinApply::getMemberId, memberId)
            .eq(FoodCompanyJoinApply::getDelFlag, DEL_NORMAL)
            .orderByDesc(FoodCompanyJoinApply::getApplyTime)
            .orderByDesc(FoodCompanyJoinApply::getCreateDate));
    }
}
