package com.microservices.zone.project.controller;

import com.alibaba.fastjson2.JSONObject;
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.project.domain.vo.*;
import com.microservices.zone.project.service.IZoneProjectService;
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 2023-05-11
 */
@Api(tags = "特色专区项目聚合接口")
@RestController
@RequestMapping("/project")
public class ZoneProjectController extends BaseController {
    @Autowired
    private IZoneProjectService zoneProjectService;

    /**
     * 查询特色专区项目聚合列表
     */
    @RequiresPermissions("zone:project:list")
    @GetMapping("/list")
    @ApiOperation("查询项目聚合列表")
    public GenericsTableDataInfo<ZoneProjectDataVo> list(ZoneProjectSearchVo zoneProjectSearchVo) {
        return zoneProjectService.selectZoneProjectList(zoneProjectSearchVo, false);
    }

    /**
     * 获取专区下项目首页推荐数量
     */
    @RequiresPermissions("zone:project:list")
    @GetMapping("/zone/{zoneId}/homepageCount")
    @ApiOperation("获取专区下项目首页推荐数量")
    public AjaxResult homepageCount(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable Long zoneId) {
        return success(zoneProjectService.selectHomepageCount(zoneId));
    }

    /**
     * 查询GitLink项目列表
     */
    @GetMapping("/zone/{zoneId}/gitlinkProjectList")
    @ApiOperation("查询专区下GitLink项目列表")
    public GenericsTableDataInfo<JSONObject> gitlinkProjectListByZone(
            @ApiParam(name = "zoneId", value = "专区Id") @PathVariable Long zoneId
            , GitLinkProjectSearchVo gitLinkProjectSearchVo) {
        return zoneProjectService.selectGitlinkProjectList(zoneId, gitLinkProjectSearchVo);
    }

    /**
     * 查询GitLink项目列表
     */
    @GetMapping("/gitlinkProjectList")
    @ApiOperation("查询GitLink项目列表")
    public GenericsTableDataInfo<JSONObject> gitlinkProjectList(GitLinkProjectSearchVo gitLinkProjectSearchVo) {
        return zoneProjectService.selectGitlinkProjectList(null, gitLinkProjectSearchVo);
    }

    /**
     * 查询GitLink项目语言列表
     */
    @GetMapping("/gitlinkProjectLanguages")
    @ApiOperation("查询GitLink项目语言列表")
    public GenericsTableDataInfo<ProjectLanguageVo> gitlinkProjectLanguages() {
        List<ProjectLanguageVo> list = zoneProjectService.selectGitlinkProjectLanguages();
        return getGenericsDataTable(list);
    }

    /**
     * 获取特色专区项目聚合详细信息
     */
    @RequiresPermissions("zone:project:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取特色专区项目聚合详细信息")
    public GenericsAjaxResult<ZoneProjectDataVo> getInfo(@PathVariable("id") Long id) {
        return GenericsAjaxResult.success(zoneProjectService.selectZoneProjectDataById(id));
    }

    /**
     * 批量新增特色专区项目聚合
     */
    @RequiresPermissions("zone:project:add")
    @Log(title = "特色专区项目聚合", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("批量新增项目聚合")
    public AjaxResult add(@RequestBody @Validated List<ZoneProjectInputVo> zoneProjectInputVoList) {
        return toAjax(zoneProjectService.insertBatchZoneProject(zoneProjectInputVoList));
    }

    /**
     * 修改特色专区项目聚合
     */
    @RequiresPermissions("zone:project:edit")
    @Log(title = "特色专区项目聚合", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/{id}")
    @ApiOperation("修改特色专区项目聚合")
    public AjaxResult edit(@PathVariable("id") Long id, @RequestBody ZoneProjectUpdateVo zoneProjectUpdateVo) {
        return toAjax(zoneProjectService.updateZoneProject(id, zoneProjectUpdateVo));
    }

    /**
     * 删除特色专区项目聚合
     */
    @RequiresPermissions("zone:project:remove")
    @Log(title = "特色专区项目聚合", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除特色专区项目聚合")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zoneProjectService.deleteZoneProjectByIds(ids));
    }

    /**
     * 设置是否首页展示
     */
    @RequiresPermissions("zone:project:homepage")
    @Log(title = "特色专区项目聚合", businessType = BusinessType.UPDATE)
    @PutMapping("/{id}/homepage")
    @ApiOperation("设置是否首页展示")
    public AjaxResult updateHomepageShow(@PathVariable Long id) {
        return toAjax(zoneProjectService.updateZoneProjectHomePageShow(id));
    }
}
