package com.yida.data.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.system.EduSchoolInquireCommonQuestion;
import com.yida.data.common.core.entity.system.EduSchoolInquirePhone;
import com.yida.data.system.service.EduInquireQuestionService;
import com.yida.data.system.vo.FindPhonePageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ccl
 */
@Slf4j
@Validated
@Api(tags = "入学咨询")
@RestController
@RequestMapping("/inquire")
@RequiredArgsConstructor
public class EduInquireController {
    private final EduInquireQuestionService inquireService;

    @ApiOperation("常见问题列表")
    @GetMapping("/findQuestionPage")
    public ResultBean<IPage<EduSchoolInquireCommonQuestion>> findQuestionPage(@RequestParam(required = false)@ApiParam("标签id") Long labelId,
                                                                              @RequestParam  @ApiParam("部门id") Long deptId,
                                                                              @RequestParam (required = false) @ApiParam("问题") String question,
                                                                              @RequestParam (required = false,defaultValue = "1")Integer pageNum,
                                                                              @RequestParam (required = false,defaultValue = "10")Integer pageSize) {

        Page page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        return ResultBean.buildSuccess(inquireService.findQuestionPage(labelId,deptId,page,question));
    }

    @ApiOperation("咨询电话列表")
    @GetMapping("/findPhonePage")
    public ResultBean<IPage<FindPhonePageVO>> findPhonePage(@RequestParam (required = false)@ApiParam("标签id") Long labelId,
                                                            @RequestParam  @ApiParam("部门id") Long deptId,
                                                            @RequestParam (required = false) @ApiParam("学校名称") String schoolName,
                                                            @RequestParam (required = false,defaultValue = "1")Integer pageNum,
                                                            @RequestParam (required = false,defaultValue = "10")Integer pageSize) {

        Page page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        return ResultBean.buildSuccess(inquireService.findPhonePage(labelId,deptId,page,schoolName));
    }

    @ApiOperation("新增或修改问题")
    @PostMapping("/saveOrUpdateQuestion")
    public ResultBean saveOrUpdateQuestion(@RequestBody List<EduSchoolInquireCommonQuestion> questionList) {

        inquireService.saveOrUpdateQuestion(questionList);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("新增或修改电话")
    @PostMapping("/saveOrUpdatePhone")
    public ResultBean saveOrUpdatePhone(@RequestBody List<EduSchoolInquirePhone> phoneList) {

        inquireService.saveOrUpdatePhone(phoneList);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除电话")
    @GetMapping("/removePhone")
    public ResultBean removePhone(@RequestParam Long phoneId) {

        inquireService.removePhone(phoneId);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除问题")
    @GetMapping("/removeQuestion")
    public ResultBean removeQuestion(@RequestParam Long questionId) {

        inquireService.removeQuestion(questionId);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("查询问题详情")
    @GetMapping("/findQuestionById")
    public ResultBean<EduSchoolInquireCommonQuestion> findQuestionById(@RequestParam Long questionId) {


        return ResultBean.buildSuccess( inquireService.findQuestionById(questionId));
    }

    @ApiOperation("查询电话详情")
    @GetMapping("/findPhoneById")
    public ResultBean<EduSchoolInquirePhone> findPhoneById(@RequestParam Long phoneId) {


        return ResultBean.buildSuccess(inquireService.findPhoneById(phoneId));
    }
}
