package jnpf.cultivate.controller.app.teaching;

import com.github.pagehelper.PageInfo;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.TeachingRecordService;
import jnpf.model.cultivate.dto.teaching.QueryTeachingRecordDto;
import jnpf.model.cultivate.dto.teaching.TeachingSaveDto;
import jnpf.model.cultivate.vo.teaching.*;
import jnpf.util.FtbUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 带教管理
 */
@Slf4j
@RestController
@RequestMapping("/app/teachingRecord")
public class AppTeachingController{

    @Autowired
    private TeachingRecordService teachingRecordService;

    /**
     * 获取学员下拉列表
     * @param storeId 门店ID，用于筛选指定门店的学员
     * @return 返回学员信息列表，封装在ActionResult中
     */
    @GetMapping("/getStudentList")
    public ActionResult<List<PositionUserVo>> getStudentList(@RequestParam("storeId") String storeId) {
        List<PositionUserVo> postUserList = teachingRecordService.getPostUserList(storeId);
        return ActionResult.success(postUserList);
    }

    /**
     * 我的带教-列表分页查询
     * @param queryTeachingRecordDto 查询条件封装对象，包含分页参数和查询条件
     * @return 分页查询结果，包含带教记录列表和分页信息
     */
    @GetMapping("/page")
    public ActionResult<PageListVO<TeachingRecordVo>> page(QueryTeachingRecordDto queryTeachingRecordDto) {
        PageInfo<TeachingRecordVo> page = teachingRecordService.page(queryTeachingRecordDto);
        return ActionResult.page(page.getList(), FtbUtil.getPagination(page));
    }

    /**
     * 新增带教记录
     * @param teachingSaveDto 带教记录保存数据传输对象
     * @return 操作结果，成功则返回空内容
     */
    @PostMapping("/add")
    public ActionResult<Void> add(@Valid @RequestBody TeachingSaveDto teachingSaveDto) {
        teachingSaveDto.setType(1);
        teachingRecordService.add(teachingSaveDto);
        return ActionResult.success();
    }

    /**
     * 修改带教记录
     * @param teachingSaveDto 带教记录修改数据传输对象
     * @return 操作结果，成功则返回空内容
     */
    @PutMapping("/update")
    public ActionResult<Void> update(@Valid @RequestBody TeachingSaveDto teachingSaveDto) {
        teachingSaveDto.setType(1);
        teachingRecordService.update(teachingSaveDto);
        return ActionResult.success();
    }

    /**
     * 删除带教记录
     * @param id 带教记录ID
     * @return 删除操作结果，成功则返回空内容
     */
    @DeleteMapping("/delete/{id}")
    public ActionResult<Void> delete(@PathVariable("id") String id) {
        teachingRecordService.delete(id);
        return ActionResult.success();
    }

    /**
     * 我的带教 - 上级带教分页查询
     * @param queryTeachingRecordDto 查询条件封装对象
     * @return 分页查询结果，包含上级带教记录列表和分页信息
     */
    @PostMapping("/learderPage")
    public ActionResult<PageListVO<TeachingRecordVo>> learderPage(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        PageInfo<TeachingRecordVo> voPageInfo = teachingRecordService.queryMyTeachingRecordList(queryTeachingRecordDto);
        return ActionResult.page(voPageInfo.getList(), FtbUtil.getPagination(voPageInfo));
    }

    /**
     * 我的带教-查看数据统计
     * @param queryTeachingRecordDto 查询条件封装对象
     * @return 带教数据统计列表和分页信息
     */
    @PostMapping("/dataList")
    public ActionResult<PageListVO<TeachingDataListVo>> dataList(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        PageInfo<TeachingDataListVo> voPageInfo = teachingRecordService.teachingStudentDataCount(queryTeachingRecordDto);
        return ActionResult.page(voPageInfo.getList(), FtbUtil.getPagination(voPageInfo));
    }

    /**
     * 上级带教-查看技能统计数据
     * @param queryTeachingRecordDto 查询条件封装对象
     * @return 技能统计列表
     */
    @PostMapping("/learderDataList")
    public ActionResult<List<SkillCountVo>> learderDataList(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        List<SkillCountVo> skillCountVoList = teachingRecordService.queryMyTeachingData(queryTeachingRecordDto);
        return ActionResult.success(skillCountVoList);
    }

    /**
     * 查看带教员下拉列表
     * @param queryTeachingRecordDto 查询条件封装对象，包含门店ID等参数
     * @return 带教员信息列表
     */
    @PostMapping("/teachUserList")
    public ActionResult<List<TeachingUserVo>> teachUserList(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        List<TeachingUserVo> teachingUserVos = teachingRecordService.teachingSelectList(queryTeachingRecordDto);
        return ActionResult.success(teachingUserVos);
    }

    /**
     * 查看带教员下拉列表-上级带教专用
     * @param queryTeachingRecordDto 查询条件封装对象
     * @return 上级带教员信息列表
     */
    @PostMapping("/teachingSuperiorSelectList")
    public ActionResult<List<TeachingUserVo>> teachingSuperiorSelectList(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        List<TeachingUserVo> teachingUserVos = teachingRecordService.teachingSuperiorSelectList(queryTeachingRecordDto);
        return ActionResult.success(teachingUserVos);
    }

    /**
     * 获取带教记录详情
     * @param id 带教记录ID
     * @return 带教记录详细信息
     */
    @GetMapping("/detail/{id}")
    public ActionResult<TeachingRecordDetailVo> detail(@PathVariable("id") String id) {
        TeachingRecordDetailVo teachingDetail = teachingRecordService.getTeachingDetail(id);
        return ActionResult.success(teachingDetail);
    }

    /**
     * 店长界面我的带教统计
     * @param storeId 门店ID
     * @return 门店带教统计信息
     */
    @GetMapping("/storeTeachingCount")
    public TeachingStoreCountVo storeTeachingCount(@RequestParam("storeId") String storeId) {
        return teachingRecordService.storeTeachingCount(storeId);
    }

    /**
     * 带教统计总览
     * @param queryTeachingRecordDto 查询条件封装对象
     * @return 带教统计信息
     */
    @PostMapping("/teachingCount")
    public ActionResult<TeachingCountVo> teachingCount(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        TeachingCountVo teachingCountVo = teachingRecordService.teachingCount(queryTeachingRecordDto);
        return ActionResult.success(teachingCountVo);
    }

    /**
     * 员工界面-上级带教统计
     * @param storeId 门店id
     * @return TeachingStoreCountVo
     */
    @GetMapping("/getSuperiorTeachingSummary")
    public SuperiorTeachingSummaryVo getSuperiorTeachingSummary(@RequestParam("storeId") String storeId) {
        return teachingRecordService.getSuperiorTeachingSummary(storeId);
    }
}