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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgConfigPhoneNumber;
import com.yuchen.saas.park.service.service.PmgConfigPhoneNumberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author 刘通
 * @date 2020/12/12 11:01
 */
@RestController
@AllArgsConstructor
@RequestMapping("/phoneNumber")
@Api(value = "电话号码", tags = "电话号码表接口")
public class PmgConfigPhoneNumberController {
    @Autowired
    private PmgConfigPhoneNumberService pmgConfigPhoneNumberService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入电话号码信息")
    public R<PmgConfigPhoneNumber> detail(PmgConfigPhoneNumber pmgConfigPhoneNumber) {
        PmgConfigPhoneNumber detail = pmgConfigPhoneNumberService.getOne(Condition.getQueryWrapper(pmgConfigPhoneNumber));
        return R.data(detail);
    }

    /**
     * 分页 电话号码信息
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入电话号码信息")
    public R<IPage<PmgConfigPhoneNumber>> list(PmgConfigPhoneNumber pmgConfigPhoneNumber, Query query) {
        IPage<PmgConfigPhoneNumber> pages = pmgConfigPhoneNumberService.page(Condition.getPage(query),Condition.getQueryWrapper(pmgConfigPhoneNumber));
        return  R.data(pages);
    }

    /**
     * 新增 电话号码信息
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增", notes = "传入电话号码信息")
    public R save(@Valid @RequestBody PmgConfigPhoneNumber pmgConfigPhoneNumber) {
        return R.status(pmgConfigPhoneNumberService.save(pmgConfigPhoneNumber));
    }
    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增或修改", notes = "传入电话号码信息")
    public R submit(@Valid @RequestBody PmgConfigPhoneNumber pmgConfigPhoneNumber) {
        return R.status(pmgConfigPhoneNumberService.saveOrUpdate(pmgConfigPhoneNumber));
    }
    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入电话号码信息")
    public R update(@Valid @RequestBody PmgConfigPhoneNumber pmgConfigPhoneNumber) {
        return R.status(pmgConfigPhoneNumberService.updateById(pmgConfigPhoneNumber));
    }

    /**
     * 删除 电话号码信息
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(pmgConfigPhoneNumberService.deleteLogic(Func.toLongList(ids)));
    }
}
