package com.microservices.zone.journals.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.core.web.page.TableDataInfo;
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.journals.domain.ZoneJournals;
import com.microservices.zone.journals.domain.vo.ZoneJournalsInputVo;
import com.microservices.zone.journals.domain.vo.ZoneJournalsParentDataVo;
import com.microservices.zone.journals.domain.vo.ZoneJournalsSearchVo;
import com.microservices.zone.journals.domain.vo.ZoneJournalsUpdateVo;
import com.microservices.zone.journals.service.IZoneJournalsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通用评论Controller
 *
 * @author otto
 * @date 2025-04-30
 */
@RestController
@RequestMapping("/journals")
@Api(tags = "通用评论接口")
public class ZoneJournalsController extends BaseController {

    @Autowired
    private IZoneJournalsService zoneJournalsService;

    /**
     * 查询评论列表（二级结构）
     */
//    @RequiresPermissions("zone:journals:list")
    @GetMapping("/list")
    @ApiOperation("查询评论列表")
    public GenericsTableDataInfo<ZoneJournalsParentDataVo> list(ZoneJournalsSearchVo searchVo) {
        startPage();
        List<ZoneJournalsParentDataVo> list = zoneJournalsService.selectJournalsList(searchVo);
        return new GenericsTableDataInfo<>(list);
    }

    /**
     * 获取评论详细信息
     */
//    @RequiresPermissions("zone:journals:query")
    @GetMapping("/{id}")
    @ApiOperation("获取评论详细信息")
    public AjaxResult getInfo(@ApiParam(value = "评论ID", required = true) @PathVariable("id") Long id) {
        ZoneJournals zoneJournals = zoneJournalsService.selectZoneJournalsById(id);
        return success(zoneJournals);
    }

    /**
     * 新增评论
     */
//    @RequiresPermissions("zone:journals:add")
    @Log(title = "新增评论", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增评论")
    public AjaxResult add(@RequestBody @Validated ZoneJournalsInputVo inputVo) {
        Long journalId = zoneJournalsService.insertJournals(inputVo);
        return success(journalId);
    }

    /**
     * 修改评论
     */
//    @RequiresPermissions("zone:journals:edit")
    @Log(title = "修改评论", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改评论")
    public AjaxResult edit(@RequestBody @Validated ZoneJournalsUpdateVo updateVo) {
        int result = zoneJournalsService.updateJournals(updateVo);
        return toAjax(result);
    }

    /**
     * 删除评论
     */
//    @RequiresPermissions("zone:journals:remove")
    @Log(title = "删除评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @ApiOperation("删除评论")
    public AjaxResult remove(@ApiParam(value = "评论ID", required = true) @PathVariable("id") Long id) {
        int result = zoneJournalsService.deleteJournalsById(id);
        return toAjax(result);
    }

    /**
     * 批量删除评论
     */
//    @RequiresPermissions("zone:journals:remove")
    @Log(title = "批量删除评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/batch/{ids}")
    @ApiOperation("批量删除评论")
    public AjaxResult removeBatch(@ApiParam(value = "评论ID数组", required = true) @PathVariable Long[] ids) {
        int result = zoneJournalsService.deleteJournalsByIds(ids);
        return toAjax(result);
    }
}
