package com.fdkankan.platform.user.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fdkankan.common.controller.BaseController;
import com.fdkankan.platform.agent.request.RequestNote;
import com.fdkankan.platform.agent.request.RequestSearch;
import com.fdkankan.platform.user.entity.IntercomMessage;
import com.fdkankan.platform.user.request.RequestMessage;
import com.fdkankan.platform.user.service.IIntercomMessageService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 咨询留言
 */

@Log4j2
@RestController
@RequestMapping("/service/platform")
public class InterComMessageController extends BaseController {

    @Autowired
    private IIntercomMessageService interComMessageService;

    /**
     * 保存留言
     * contact  联系方式
     * content  留言内容
     */
    @RequestMapping(value = "/intercomMessage/leave", method = RequestMethod.POST)
    public String leave(@RequestBody RequestMessage message) throws Exception {
        return interComMessageService.saveByParam(message);
    }

    /**
     * 留言列表-根据邮件查询
     * email    email
     * @return
     */
    @RequestMapping(value = "/mine", method = RequestMethod.POST)
    public List<IntercomMessage> mine(@RequestBody RequestMessage message) throws Exception {
        return interComMessageService.getByEmail(message.getEmail());
    }


    /**
     * 留言列表
     *
     * @return
     */
    @GetMapping("/manager/intercomMessage/list")
    public Page<IntercomMessage> list(@RequestParam(value="pageNum", defaultValue="0", required = false) Integer pageNum,
                                      @RequestParam(value="pageSize", defaultValue="10", required = false) Integer pageSize) throws Exception {
        return interComMessageService.page(new Page<>(pageNum,pageSize),new QueryWrapper<IntercomMessage>().lambda().orderByDesc(IntercomMessage::getCreateTime));
    }


    /**
     * 更新状态
     * id           id
     * state        活动状态
     */
    @GetMapping("/manager/intercomMessage/update/active/{id}/{state}")
    private String updateActive(@PathVariable("id") Long id, @PathVariable("state") String state){
        return interComMessageService.updateActive(id,state);
    }


    /**
     * 更新备注信息
     * id
     * noteType         备注登记
     * noteContent      备注内容
     */
    @PostMapping("/manager/intercomMessage/update/note")
    private String updateNote(@RequestBody RequestNote param){
        return interComMessageService.updateNote(param);
    }


    /**
     * 模糊查询
     * startDate    开始时间
     * endDate      结束时间
     * itemName     项目名称
     * @return
     */
    @PostMapping("/manager/intercomMessage/search")
    private Page<IntercomMessage> search(@RequestBody RequestSearch param) {
        return interComMessageService.searchLike(param);
    }

}
