package com.yuchen.saas.park.service.controller.property;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.dto.property.PropertyAdsPositionQryDto;
import com.yuchen.saas.park.api.entity.property.PropertyAdsPosition;
import com.yuchen.saas.park.api.vo.property.PropertyAdsPositionListVo;
import com.yuchen.saas.park.service.service.property.PropertyAdsPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "广告位管理")
@RestController
@RequestMapping("/propertyAdsPosition")
public class PropertyAdsPositionController {
    @Autowired
    private PropertyAdsPositionService propertyAdsPositionService;

    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "广告位新增")
    public R save(@Valid @RequestBody PropertyAdsPosition propertyAdsPosition) {
        return R.status(propertyAdsPositionService.saveAdsPosition(propertyAdsPosition));
    }

    @PostMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "广告位列表")
    public R<Page<PropertyAdsPositionListVo>> list(@RequestBody PropertyAdsPositionQryDto propertyAdsPositionQryDto) {
        return R.data(propertyAdsPositionService.selectPage(propertyAdsPositionQryDto));
    }

    @GetMapping("/detail")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "详情", notes = "广告位详情")
    public R<PropertyAdsPosition> detail(@RequestParam("id") Long id) {
        return R.data(propertyAdsPositionService.getById(id));
    }

    @PostMapping("/delete")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "广告位删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        return R.data(propertyAdsPositionService.removeById(param.getId()));
    }

}
