package com.microservices.zone.detail.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.Logical;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.zone.detail.domain.ZoneApplication;
import com.microservices.zone.detail.domain.vo.ZoneApplicationCreateZoneVo;
import com.microservices.zone.detail.domain.vo.ZoneApplicationSearchVo;
import com.microservices.zone.detail.service.IZoneApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 特色专区申请Controller
 *
 * @author microservices
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/application")
@Api(tags = "特色专区申请接口")
public class ZoneApplicationController extends BaseController
{
    @Autowired
    private IZoneApplicationService zoneApplicationService;

    /**
     * 查询特色专区申请列表
     */
    @RequiresPermissions("zone:application:list")
    @GetMapping("/list")
    public GenericsTableDataInfo<ZoneApplication> list(ZoneApplicationSearchVo zoneApplicationSearchVo)
    {
        return zoneApplicationService.selectZoneApplicationListBySearchInput(zoneApplicationSearchVo);
    }

    /**
     * 获取特色专区申请详细信息
     */
    @RequiresPermissions("zone:application:query")
    @GetMapping(value = "/{id}")
    public GenericsAjaxResult<ZoneApplication> getInfo(@PathVariable("id") Long id)
    {
        return genericsSuccess(zoneApplicationService.selectZoneApplicationById(id));
    }

    /**
     * 新增特色专区申请
     */
    @Log(title = "特色专区申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZoneApplication zoneApplication)
    {
        return toAjax(zoneApplicationService.insertZoneApplication(zoneApplication));
    }

    /**
     * 修改特色专区申请
     */
    @RequiresPermissions("zone:application:edit")
    @Log(title = "特色专区申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZoneApplication zoneApplication)
    {
        return toAjax(zoneApplicationService.updateZoneApplication(zoneApplication));
    }

    /**
     * 删除特色专区申请
     */
    @RequiresPermissions("zone:application:remove")
    @Log(title = "特色专区申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zoneApplicationService.deleteZoneApplicationByIds(ids));
    }

    /**
     * 基于专区申请创建专区
     */
    @RequiresPermissions(value = {"zone:application:createZone", "system:dept:add"}, logical = Logical.OR)
    @Log(title = "特色专区申请", businessType = BusinessType.INSERT)
    @PostMapping("/{id}")
    @ApiOperation(value = "基于专区申请创建专区")
    public AjaxResult createZoneByApplication(@PathVariable Long id, @RequestBody ZoneApplicationCreateZoneVo zoneApplicationCreateZoneVo) {
        return success(zoneApplicationService.createZoneByApplication(id, zoneApplicationCreateZoneVo));
    }
}
