package com.slodon.b2b2c.controller.system.admin;

import com.slodon.b2b2c.core.response.JsonResult;
import com.slodon.b2b2c.core.response.SldResponse;
import com.slodon.b2b2c.aop.OperationLogger;
import com.slodon.b2b2c.core.util.AssertUtil;
import com.slodon.b2b2c.model.system.PcFirstAdvModel;
import com.slodon.b2b2c.system.pojo.PcFirstAdv;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "admin-首页首页广告设置设置（开屏图、顶部广告）")
@RestController
@RequestMapping("v3/system/admin/pcFirstAdv")
public class AdminPcFirstAdvController {

    @Resource
    private PcFirstAdvModel pcFirstAdvModel;

    @ApiOperation("获取pc首页广告")
    @GetMapping("get")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "广告类型,1-弹层广告，2-顶部广告", required = false,defaultValue = "1")
    })
    public JsonResult<PcFirstAdv> get(@RequestParam(value = "type",required = false,defaultValue = "1") Integer type) {
        AssertUtil.isTrue(type != 1 && type != 2 ,"参数不对");
        PcFirstAdv pcFirstAdv = pcFirstAdvModel.getPcFirstAdvByAdvId(type);
        return SldResponse.success(pcFirstAdv);
    }

    @ApiOperation("更新pc首页弹层广告")
    @OperationLogger(option = "更新pc首页广告")
    @PostMapping("update")
    public JsonResult update(HttpServletRequest request, PcFirstAdv pcFirstAdv) {
        pcFirstAdvModel.updatePcFirstAdv(pcFirstAdv);
        return SldResponse.success("更新成功");
    }
}
