package com.yida.data.school.index.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.entity.school.EduDeptHomeApp;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.dto.index.SaveDeptHomeAppDTO;
import com.yida.data.school.index.service.EduDeptHomeAppService;
import com.yida.data.school.vo.index.ContactVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 部门微官网应用配置 Controller
 *
 * @author ZYJ
 * @date 2023-06-28 15:24:25
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("eduDeptHomeApp")
@Api(tags = "部门微官网应用配置api")
public class EduDeptHomeAppController {

    private final EduDeptHomeAppService eduDeptHomeAppService;

    @ApiOperation("应用列表")
    @PostMapping("/listApp")
    public ResultBean<List<EduDeptHomeApp>> listApp(@RequestBody EduDeptHomeApp app) {
        return ResultBean.buildSuccess(eduDeptHomeAppService
            .list(Wrappers.<EduDeptHomeApp>lambdaQuery().eq(EduDeptHomeApp::getDeptId, FebsUtil.getDeptId())
                .eq(ObjectUtil.isNotEmpty(app.getAppType()), EduDeptHomeApp::getAppType, app.getAppType())
                .eq(ObjectUtil.isNotEmpty(app.getUserType()), EduDeptHomeApp::getUserType, app.getUserType())
                .like(ObjectUtil.isNotEmpty(app.getName()), EduDeptHomeApp::getName, app.getName())
                .orderByAsc(EduDeptHomeApp::getSort)));
    }

    @ApiOperation("添加/编辑应用")
    @PostMapping("/addApp")
    public ResultBean<String> addDeptHomeApp(@Validated @RequestBody SaveDeptHomeAppDTO dto) {
        eduDeptHomeAppService.addDeptHomeApp(dto);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除应用")
    @GetMapping("/deleteApp")
    public ResultBean<String> deleteDeptHomeApp(@RequestParam Long id) {
        eduDeptHomeAppService.removeById(id);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("应用详情")
    @GetMapping("/getApp")
    public ResultBean<EduDeptHomeApp> getApp(@RequestParam Long id) {
        return ResultBean.buildSuccess(eduDeptHomeAppService.getById(id));
    }

    @ApiOperation("启用/停用应用")
    @GetMapping("/enableApp")
    public ResultBean<String> enableApp(@ApiParam("主键ID") @RequestParam Long id,
        @ApiParam("启用状态：0:停用,1:启用") @RequestParam Integer status) {
        eduDeptHomeAppService.enableApp(id, status);
        return ResultBean.buildSuccess();
    }
}
