package com.bohuikeji.delivery.backstage.controller.api.v2;

import com.bohuikeji.frame.module.admin.base.ApiController;
import com.bohuikeji.frame.module.admin.component.RedisUtil;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import com.bohuikeji.frame.module.admin.entity.sys.SysConfig;
import com.bohuikeji.frame.module.admin.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 广告配置API
 * @author 孙劲辉
 */
@Api(tags = {"广告配置API"})
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/ad/v2")
@Slf4j
public class AdV2Api extends ApiController {


    final ISysConfigService configService;
    final RedisUtil redisUtil;


    @ApiOperation("获取广告详情")
    @GetMapping("/get/id")
    @ApiImplicitParams({
            @ApiImplicitParam(name="configKey",value="广告ID",dataType="int", paramType = "query")})
    public APIEntity<SysConfig> getId(Integer id){
        SysConfig sysConfig = configService.getById(id);
        if(sysConfig==null){
            return APIEntity.fail("未找到配置项信息！");
        }
        return APIEntity.success(sysConfig);
    }

    @ApiOperation("获取广告详情")
    @GetMapping("/get/key")
    @ApiImplicitParams({
            @ApiImplicitParam(name="configKey",value="广告KEY",dataType="String", paramType = "query")})
    public APIEntity<SysConfig> getKey(String configKey){
        SysConfig sysConfig = configService.getOneByKey(configKey);
        if(sysConfig==null){
            return APIEntity.fail("未找到配置项信息！");
        }
        return APIEntity.success(sysConfig);
    }

    @ApiOperation("获取广告列表")
    @GetMapping("/get/group")
    @ApiImplicitParams({
            @ApiImplicitParam(name="configGroup",value="广告组KEY",dataType="String", paramType = "query")})
    public APIEntity<List<SysConfig>> getGroup(String configGroup){
        List<SysConfig> sysConfigList = configService.getListByGroup(configGroup);
        return APIEntity.success(sysConfigList);
    }


}
