package com.cool.store.dao;

import com.cool.store.request.close.file.CloseStoreMailAddressRequest;
import com.cool.store.entity.CloseStoreFileDetailDO;
import com.cool.store.mapper.CloseStoreFileDetailMapper;
import com.cool.store.request.close.file.CloseStoreFileApproveRequest;
import com.cool.store.request.close.file.CloseStoreMailInfoRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

/**
 * <p>
 * 闭店资料详情DAO
 * </p>
 *
 * @author wangff
 * @since 2025/10/7
 */
@RequiredArgsConstructor
@Repository
public class CloseStoreFileDetailDAO {
    private final CloseStoreFileDetailMapper closeStoreFileDetailMapper;

    /**
     * 新增或编辑闭店资料邮寄地址信息
     * @param request 闭店资料邮寄地址信息Request
     * @return boolean
     */
    public boolean insertOrUpdateMailAddress(CloseStoreMailAddressRequest request) {
        return closeStoreFileDetailMapper.insertOrUpdateMailAddress(request) > 0;
    }

    /**
     * 新增或编辑闭店资料邮寄信息
     * @param request 闭店资料邮寄信息Request
     * @param mailStatus 邮寄状态
     */
    public void insertOrUpdateMailInfo(CloseStoreMailInfoRequest request, Boolean mailStatus) {
        closeStoreFileDetailMapper.insertOrUpdateMailInfo(request, mailStatus);
    }

    /**
     * 新增或编辑闭店资料信息
     *
     * @param request 闭店材料审批Request
     */
    public void insertOrUpdateFileInfoSelective(CloseStoreFileApproveRequest request, Boolean approveComplete) {
        closeStoreFileDetailMapper.insertOrUpdateFileInfoSelective(request, approveComplete);
    }

    /**
     * 根据闭店申请id查询
     * @param closeStoreId 闭店申请id
     * @return 闭店资料详情
     */
    public CloseStoreFileDetailDO getByCloseStoreId(Long closeStoreId) {
        return closeStoreFileDetailMapper.selectOne(CloseStoreFileDetailDO.builder().closeStoreId(closeStoreId).build());
    }

    /**
     * 初始化数据
     * @param closeStoreId 闭店申请id
     */
    public void init(Long closeStoreId) {
        CloseStoreFileDetailDO detailDO = CloseStoreFileDetailDO.builder().closeStoreId(closeStoreId).build();
        closeStoreFileDetailMapper.insertSelective(detailDO);
    }

    public void updateByCloseStoreIdSelective(CloseStoreFileDetailDO detailDO) {
        Example example = new Example(CloseStoreFileDetailDO.class);
        example.createCriteria().andEqualTo("closeStoreId", detailDO.getCloseStoreId());
        closeStoreFileDetailMapper.updateByExampleSelective(detailDO, example);
    }
}
