package com.yuchen.saas.park.service.service.property.bill;

import cn.hutool.extra.spring.SpringUtil;
import com.yuchen.saas.park.api.dto.property.CreateBillDto;
import com.yuchen.saas.park.api.enums.property.CreateBillTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.log.exception.ServiceException;
import org.springframework.stereotype.Service;

/**
 * 账单生成统一入口
 */
@Slf4j
@Service
public class PropertyBillFactoryService {


    /**
     * 账单生成
     * @param createBillDto
     */
    public void createBill(CreateBillDto createBillDto) {
        this.service(createBillDto.getCreateBillTypeEnum()).createBill(createBillDto);
    }



    /**
     * 根据账单类型获取对应服务
     * @param createBillTypeEnum
     * @return
     */
    private IPropertyBillService service(CreateBillTypeEnum createBillTypeEnum) {
        switch (createBillTypeEnum) {
            case CYCLE:
                return SpringUtil.getBean(CycleBillServiceImpl.class);
            case METER:
                return SpringUtil.getBean(MeterBillServiceImpl.class);
            case SHARE_FEE:
                return SpringUtil.getBean(ShareFeeBillServiceImpl.class);
            case DEPOSIT:
                return SpringUtil.getBean(DepositBillServiceImpl.class);
            case TEMPORARY:
                return SpringUtil.getBean(TemporaryBillServiceImpl.class);
            case BILL_SPLIT:
                return SpringUtil.getBean(SlipBillServiceImpl.class);
            case BUSINESS:
                return SpringUtil.getBean(BusinessBillServiceImpl.class);
            default:
                throw new ServiceException("CreateBillTypeEnum = " + createBillTypeEnum +" 未找到对应服务！");
        }
    }






}
