package com.engine.salary.entity.agency.bo;

import com.engine.salary.entity.agency.dto.PaymentAgencyFormDTO;
import com.engine.salary.entity.agency.dto.PaymentAgencyListDTO;
import com.engine.salary.entity.agency.po.PaymentAgencyPO;
import com.engine.salary.enums.sicategory.DeleteTypeEnum;
import com.engine.salary.util.db.IdGenerator;
import org.apache.commons.collections4.CollectionUtils;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


public class PaymentAgencyBO {

//    public static Wrapper<PaymentAgencyPO> buildPaymentAgencyListWrapper(Long employeeId, String tenantKey) {
//        LambdaQueryWrapper<PaymentAgencyPO> lambdaQueryWrapper = Wrappers.lambdaQuery();
//        lambdaQueryWrapper.eq(PaymentAgencyPO::getTenantKey, tenantKey);
//        lambdaQueryWrapper.eq(PaymentAgencyPO::getDeleteType, DeleteTypeEnum.NOT_DELETED.getValue());
//        lambdaQueryWrapper.orderByDesc(PaymentAgencyPO::getUpdateTime);
//        return lambdaQueryWrapper;
//    }

    public static List<PaymentAgencyListDTO> buildPaymentAgencyDTOList(List<PaymentAgencyPO> paymentAgencyPOS, Long employeeId, String tenantKey) {
        if (CollectionUtils.isEmpty(paymentAgencyPOS)) {
            return Collections.emptyList();
        }
        return paymentAgencyPOS.stream().map(e -> PaymentAgencyListDTO.builder()
            .id(e.getId())
            .agencyName(e.getAgencyName())
            .remarks(e.getRemarks()).build()
        ).collect(Collectors.toList());
    }

    public static PaymentAgencyFormDTO buildPaymentAgencyFormDTO(PaymentAgencyPO paymentAgencyPO, Long employeeId, String tenantKey) {
        PaymentAgencyFormDTO paymentAgencyFormDTO = PaymentAgencyFormDTO.builder().build();
        paymentAgencyFormDTO.setId(paymentAgencyPO.getId());
        paymentAgencyFormDTO.setAgencyName(paymentAgencyPO.getAgencyName());
        paymentAgencyFormDTO.setRemarks(paymentAgencyFormDTO.getRemarks());
        return paymentAgencyFormDTO;
    }

    public static PaymentAgencyPO buildPaymentAgencyPO(PaymentAgencyFormDTO paymentAgencyFormDTO, Long employeeId, String tenantKey) {
        return PaymentAgencyPO.builder()
            .id(IdGenerator.generate())
            .agencyName(paymentAgencyFormDTO.getAgencyName())
            .createTime(LocalDateTime.now())
            .creator(employeeId)
            .tenantKey(tenantKey)
            .deleteType(DeleteTypeEnum.NOT_DELETED.getValue())
            .updateTime(LocalDateTime.now())
            .remarks(paymentAgencyFormDTO.getRemarks())
            .build();
    }
}
