/*
 * The MIT License (MIT)
 *
 * Copyright © 2021 xrv <xrg@live.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.tzld.piaoquan.ad.engine.commons.feign.manager.service;

import com.tzld.piaoquan.ad.engine.commons.feign.CommonResponse;
import com.tzld.piaoquan.ad.engine.commons.feign.manager.HolidayCalendarFeign;
import com.tzld.piaoquan.ad.engine.commons.feign.manager.vo.HolidayCalendarVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 节日查询服务
 *
 * @author ad-engine
 * @since 2025-08-22
 */
@Slf4j
@Service
public class HolidayService {
    
    @Autowired
    private HolidayCalendarFeign holidayCalendarFeign;
    
    /**
     * 判断今日是否是节日
     *
     * @return 节日信息，如果不是节日返回null
     */
    public HolidayCalendarVO getTodayHoliday() {
        try {
            CommonResponse<HolidayCalendarVO> response = holidayCalendarFeign.isHoliday();
            
            if (response != null && response.isSuccess()) {
                HolidayCalendarVO holiday = response.getData();
                if (holiday != null) {
                    log.info("今日是节日：{}", holiday.getHolidayName());
                } else {
                    log.info("今日不是节日");
                }
                return holiday;
            } else {
                log.error("节日查询接口调用失败，错误码：{}，错误信息：{}", 
                    response != null ? response.getCode() : "null", 
                    response != null ? response.getMsg() : "response is null");
                return null;
            }
        } catch (Exception e) {
            log.error("调用节日查询接口异常", e);
            return null;
        }
    }
    
    /**
     * 判断今日是否是节日（简化版）
     *
     * @return true-是节日，false-不是节日
     */
    public boolean isTodayHoliday() {
        return getTodayHoliday() != null;
    }
    

}
