package com.ytpm.controller;

import com.ytpm.agent.param.PlacementListParam;
import com.ytpm.agent.param.PlacementParam;
import com.ytpm.agent.view.AgentPlacementView;
import com.ytpm.agent.view.AgentUserInfo;
import com.ytpm.general.Result;
import com.ytpm.general.ResultTable;
import com.ytpm.service.PlacementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(tags = "应用内广告位管理")
@RestController
@RequestMapping("/placement")
public class AgentPlacementController {

    @Resource
    private PlacementService placementService;

    /**
     * 查询广告位列表
     */
    @ApiOperation("广告位列表")
    @PostMapping("/list")
    public ResultTable<AgentPlacementView> placementList(@RequestBody PlacementListParam param){
        return placementService.placementList(param);
    }

    /**
     * 保存广告位
     */
    @ApiOperation("保存广告位")
    @PostMapping("/save")
    public Result<?> savePlacement(@RequestBody PlacementParam param,@ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo){
        return placementService.savePlacement(param,userInfo.getUserId());
    }

    /**
     * 删除广告位
     */
    @ApiOperation("删除广告位")
    @GetMapping("/del")
    public Result<?> delPlacement(@RequestParam("placementId") String placementId,@ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo){
        return placementService.delPlacement(placementId,userInfo.getUserId());
    }
}
