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.ZoneMemberType;
import com.microservices.zone.member.domain.vo.ZoneMemberTypeInputVo;
import com.microservices.zone.member.domain.vo.ZoneMemberTypeSearchVo;
import com.microservices.zone.member.domain.vo.ZoneMemberTypeUpdateVo;
import com.microservices.zone.member.service.IZoneMemberTypeService;
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-16
 */
@RestController
@RequestMapping("/memberType")
@Api(tags = "特色专区会员类别接口")
public class ZoneMemberTypeController extends BaseController {
    @Autowired
    private IZoneMemberTypeService zoneMemberTypeService;

    /**
     * 查询特色专区会员类别列表
     */
    @RequiresPermissions("zone:memberType:list")
    @GetMapping("/list")
    @ApiOperation("查询特色专区会员类别列表")
    public GenericsTableDataInfo<ZoneMemberType> list(ZoneMemberTypeSearchVo zoneMemberTypeSearchVo) {
        startPage();
        List<ZoneMemberType> list = zoneMemberTypeService.selectZoneMemberTypeList(zoneMemberTypeSearchVo.toZoneMemberType());
        return getGenericsDataTable(list);
    }

    /**
     * 获取特色专区会员类别详细信息
     */
    @RequiresPermissions("zone:memberType:query")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取特色专区会员类别详细信息")
    public GenericsAjaxResult<ZoneMemberType> getInfo(@PathVariable("id") Long id) {
        return genericsSuccess(zoneMemberTypeService.selectZoneMemberTypeById(id));
    }

    /**
     * 新增特色专区会员类别
     */
    @RequiresPermissions("zone:memberType:add")
    @Log(title = "特色专区会员类别", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增特色专区会员类别")
    public AjaxResult add(@RequestBody ZoneMemberTypeInputVo zoneMemberTypeInputVo) {
        return toAjax(zoneMemberTypeService.insertZoneMemberType(zoneMemberTypeInputVo.toZoneMemberType()));
    }

    /**
     * 修改特色专区会员类别
     */
    @RequiresPermissions("zone:memberType:edit")
    @Log(title = "特色专区会员类别", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改特色专区会员类别")
    public AjaxResult edit(@RequestBody ZoneMemberTypeUpdateVo zoneMemberTypeUpdateVo) {
        return toAjax(zoneMemberTypeService.updateZoneMemberType(zoneMemberTypeUpdateVo));
    }

    /**
     * 删除特色专区会员类别
     */
    @RequiresPermissions("zone:memberType:remove")
    @Log(title = "特色专区会员类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除特色专区会员类别")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zoneMemberTypeService.deleteZoneMemberTypeByIds(ids));
    }
}
