package org.jeecg.modules.xcx.conf.service.impl;

import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.hotelconf.entity.HotelConf;
import org.jeecg.modules.hotelconf.service.IHotelConfService;
import org.jeecg.modules.xcx.conf.service.IConfService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Service
public class ConfServiceImpl implements IConfService {

    @Resource
    private IHotelConfService hotelConfService;

    @Override
    public Result<?> getCustomer() {
        HotelConf customerService = hotelConfService.lambdaQuery()
                .eq(HotelConf::getName, "customerService")
                .eq(HotelConf::getDelFlag, 0)
                .one();
        return Result.OK(customerService.getValue());
    }

    @Override
    public Result<?> getCoupon() {
        Map<String, Object> map = new HashMap<>();
        Integer couponFlag = Integer.parseInt(hotelConfService.getConf("couponFlag"));
        BigDecimal couponPrice = new BigDecimal(hotelConfService.getConf("couponPrice"));
        BigDecimal couponCondition = new BigDecimal(hotelConfService.getConf("couponCondition"));

        Integer leaseCouponFlag = Integer.parseInt(hotelConfService.getConf("leaseCouponFlag"));
        BigDecimal leaseCouponPrice = new BigDecimal(hotelConfService.getConf("leaseCouponPrice"));
        BigDecimal leaseCouponCondition = new BigDecimal(hotelConfService.getConf("leaseCouponCondition"));
        map.put("couponFlag",couponFlag);
        map.put("couponPrice",couponPrice);
        map.put("couponCondition",couponCondition);
        map.put("leaseCouponFlag",leaseCouponFlag);
        map.put("leaseCouponPrice",leaseCouponPrice);
        map.put("leaseCouponCondition",leaseCouponCondition);
        return Result.OK(map);
    }

    @Override
    public Result<?> getConf(String name) {
        return Result.OK(hotelConfService.getConf(name));
    }
}
