package com.microservices.zone.member.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.zone.member.domain.ZoneMemberLevel;
import com.microservices.zone.member.domain.vo.ZoneMemberLevelInputVo;
import com.microservices.zone.member.domain.vo.ZoneMemberLevelSearchVo;
import com.microservices.zone.member.domain.vo.ZoneMemberLevelUpdateVo;
import com.microservices.zone.member.service.IZoneMemberLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 特色专区会员身份Controller
 *
 * @author otto
 * @date 2023-05-26
 */
@RestController
@RequestMapping("/memberLevel")
@Api(tags = "特色专区会员身份接口")
public class ZoneMemberLevelController extends BaseController {
    @Autowired
    private IZoneMemberLevelService zoneMemberLevelService;

    /**
     * 查询特色专区会员身份列表
     */
    @RequiresPermissions("zone:memberLevel:list")
    @GetMapping("/list")
    @ApiOperation("查询特色专区会员身份列表")
    public GenericsTableDataInfo<ZoneMemberLevel> list(ZoneMemberLevelSearchVo zoneMemberLevelSearchVo) {
        startPage();
        List<ZoneMemberLevel> list = zoneMemberLevelService.selectZoneMemberLevelList(zoneMemberLevelSearchVo.toZoneMemberLevel());
        return getGenericsDataTable(list);
    }

    /**
     * 获取特色专区会员身份详细信息
     */
    @RequiresPermissions("zone:memberLevel:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取特色专区会员身份详细信息")
    public GenericsAjaxResult<ZoneMemberLevel> getInfo(@PathVariable("id") Long id) {
        return genericsSuccess(zoneMemberLevelService.selectZoneMemberLevelById(id));
    }

    /**
     * 新增特色专区会员身份
     */
    @RequiresPermissions("zone:memberLevel:add")
    @Log(title = "特色专区会员身份", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增特色专区会员身份")
    public AjaxResult add(@RequestBody ZoneMemberLevelInputVo zoneMemberLevelInputVo) {
        return toAjax(zoneMemberLevelService.insertZoneMemberLevel(zoneMemberLevelInputVo.toZoneMemberLevel()));
    }

    /**
     * 修改特色专区会员身份
     */
    @RequiresPermissions("zone:memberLevel:edit")
    @Log(title = "特色专区会员身份", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改特色专区会员身份")
    public AjaxResult edit(@RequestBody ZoneMemberLevelUpdateVo zoneMemberLevelUpdateVo) {
        return toAjax(zoneMemberLevelService.updateZoneMemberLevel(zoneMemberLevelUpdateVo));
    }

    /**
     * 删除特色专区会员身份
     */
    @RequiresPermissions("zone:memberLevel:remove")
    @Log(title = "特色专区会员身份", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除特色专区会员身份")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zoneMemberLevelService.deleteZoneMemberLevelByIds(ids));
    }
}
