package com.ycwl.basic.integration.scenic.example;

import com.ycwl.basic.integration.scenic.dto.config.CreateConfigRequest;
import com.ycwl.basic.integration.scenic.dto.filter.FilterCondition;
import com.ycwl.basic.integration.scenic.dto.filter.ScenicFilterRequest;
import com.ycwl.basic.integration.scenic.dto.scenic.CreateScenicRequest;
import com.ycwl.basic.integration.scenic.service.ScenicConfigIntegrationService;
import com.ycwl.basic.integration.scenic.service.ScenicIntegrationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collections;

/**
 * ZT-Scenic集成服务使用示例
 * 仅供参考，实际使用时根据业务需要调用相应的服务方法
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ScenicIntegrationExample {
    
    private final ScenicIntegrationService scenicIntegrationService;
    private final ScenicConfigIntegrationService scenicConfigIntegrationService;
    
    /**
     * 示例：创建景区并设置配置
     */
    public void createScenicWithConfig() {
        try {
            // 1. 创建景区
            CreateScenicRequest createRequest = new CreateScenicRequest();
            createRequest.setName("测试景区");
            createRequest.setMpId(1001);
            
            var scenic = scenicIntegrationService.createScenic(createRequest);
            log.info("创建景区成功: {}", scenic.getName());
            
            // 2. 为景区添加配置
            CreateConfigRequest configRequest = new CreateConfigRequest();
            configRequest.setConfigKey("tour_time");
            configRequest.setConfigValue("120");
            configRequest.setConfigType("int");
            configRequest.setDescription("游览时长");
            
            var config = scenicConfigIntegrationService.createConfig(
                Long.valueOf(scenic.getId()), configRequest);
            log.info("创建配置成功: {} = {}", config.getConfigKey(), config.getConfigValue());
            
        } catch (Exception e) {
            log.error("创建景区和配置失败", e);
        }
    }
    
    /**
     * 示例：筛选景区
     */
    public void filterScenics() {
        try {
            FilterCondition condition = new FilterCondition();
            condition.setConfigKey("tour_time");
            condition.setConfigValue("120");
            condition.setOperator("gte");
            
            ScenicFilterRequest filterRequest = new ScenicFilterRequest();
            filterRequest.setFilters(Collections.singletonList(condition));
            filterRequest.setPage(1);
            filterRequest.setPageSize(10);
            
            var result = scenicIntegrationService.filterScenics(filterRequest);
            log.info("筛选到 {} 个景区", result.getTotal());
            
        } catch (Exception e) {
            log.error("筛选景区失败", e);
        }
    }
}