package com.ytpm.controller;

import com.ytpm.agent.param.AdSourceListParam;
import com.ytpm.agent.param.AdSourceParam;
import com.ytpm.agent.view.AgentAdSourceView;
import com.ytpm.agent.view.AgentUserInfo;
import com.ytpm.general.Result;
import com.ytpm.general.ResultTable;
import com.ytpm.service.impl.AdSourceServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(tags = "广告源管理模块")
@RestController
@RequestMapping("/adSource")
public class AgentAdSourceController {
    @Resource
    private AdSourceServiceImpl adSourceService;


    /**
     * 获取广告源列表
     */
    @ApiOperation("获取广告源列表")
    @PostMapping("/list")
    public ResultTable<AgentAdSourceView> list(@RequestBody AdSourceListParam param,@ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo) {
        return adSourceService.adSourceList(param);
    }

    /**
     * 新增广告源
     */
    @ApiOperation("新增广告源")
    @PostMapping("/addOne")
    public Result<?> addOne(@RequestBody AdSourceParam param,@ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo){
        return adSourceService.addOne(param);
    }

    /**
     * 修改广告源
     */
    @ApiOperation("修改广告源")
    @PostMapping("/updateOne")
    public Result<?> updateOne(@RequestBody AdSourceParam param){
        return adSourceService.updateOne(param);
    }

    /**
     * 删除广告渠道
     */
    @ApiOperation("删除广告源")
    @GetMapping("/deleteOne")
    public Result<?> deleteOne(@RequestParam("adSourceId")Integer adSourceId,@ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo){
        return adSourceService.deleteOne(adSourceId,userInfo.getUserId());
    }

}
