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

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.index.service.EduSchoolHomeContactService;
import com.yida.data.school.vo.index.ContactVO;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "通讯录")
@Slf4j
@RestController
@RequestMapping("/index/contact")
@RequiredArgsConstructor
public class EduSchoolContactController {

    private final EduSchoolHomeContactService eduSchoolHomeContactService;

    @ApiOperation("查询通讯录列表")
    @GetMapping("/listContact")
    public ResultBean<ContactVO> listContact(@ApiParam("用户Id") Long userId,
        @ApiParam("用户类型，0-家长，1-教师") Integer type,
        @ApiParam("查询类型，0-家长，1-教师（用于教师查询通讯录人员列表，家长查询通讯录不传）") Integer personType,
        @ApiParam("用户名") @RequestParam(required = false) String name) {
        CurrentUser currentUser = FebsUtil.getCurrentUser();
        if (currentUser.getDeptType() == 0) {
            return ResultBean.buildSuccess(eduSchoolHomeContactService.listContact(userId, type, personType
                , name, currentUser.getDeptId()));
        }
        return ResultBean.buildSuccess();
    }
}
