package jnpf.attendance.controller;

import com.github.pagehelper.PageInfo;
import jnpf.attendance.service.UsualPhoneService;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.attendance.dto.CancelPhoneDto;
import jnpf.model.attendance.dto.UsualPhoneQueryDto;
import jnpf.model.attendance.dto.UsualPhoneSettingDto;
import jnpf.model.attendance.vo.attendance.UsualPhonePageVo;
import jnpf.util.FtbUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 常用设备管理
 *
 * @author yanwenfu
 * @create 2025-09-17
 */
@RestController
@RequestMapping(value = "/user-phone")
public class UserPhoneController {

    @Resource
    private UsualPhoneService usualPhoneService;

    /**
     * 批量取消绑定
     * @param cancelPhoneDto 取消绑定参数
     * @return java.lang.Object
     */
    @PutMapping(value = "/cancel")
    public Object cancelPhoneBatch(@RequestBody @Valid CancelPhoneDto cancelPhoneDto) {

        usualPhoneService.cancelPhoneBatch(cancelPhoneDto);
        return ActionResult.success();
    }

    /**
     * 更新常用手机设置
     * @param usualPhoneSettingDto 常用手机设置dto
     * @return java.lang.Object
     */
    @PutMapping(value = "/setting")
    public Object updateUsualPhoneSetting(@RequestBody @Valid UsualPhoneSettingDto usualPhoneSettingDto) {

        usualPhoneService.updateUsualPhoneSetting(usualPhoneSettingDto);
        return ActionResult.success();
    }

    /**
     * 查询常用手机列表(分页)
     * @param queryDto 查询条件
     * @return jnpf.base.ActionResult<jnpf.base.vo.PageListVO<jnpf.model.attendance.vo.attendance.UsualPhonePageVo>>
     */
    @GetMapping(value = "/page")
    public ActionResult<PageListVO<UsualPhonePageVo>> getUsualPhonePage(UsualPhoneQueryDto queryDto) {

        PageInfo<UsualPhonePageVo> page = usualPhoneService.getUsualPhonePage(queryDto);
        return ActionResult.page(page.getList(), FtbUtil.getPagination(page));
    }

    /**
     * 检查常用设备是否异常
     * @param phoneName 手机名称
     * @return jnpf.base.ActionResult<java.lang.Boolean>
     */
    @GetMapping(value = "/abnormal")
    public ActionResult<Boolean> checkUsualPhone(@RequestParam(value = "phoneName") String phoneName, @RequestParam(value = "phoneCode") String phoneCode) {

        Boolean flag = usualPhoneService.checkUsualPhone(phoneName, phoneCode);
        return ActionResult.success(flag);
    }

    /**
     * 查询常用手机配置
     * @return jnpf.base.ActionResult<jnpf.model.attendance.dto.UsualPhoneSettingDto>
     */
    @GetMapping(value = "/usual-phone/setting")
    public ActionResult<UsualPhoneSettingDto> getUsualPhoneSetting() {

        UsualPhoneSettingDto dto = usualPhoneService.getUsualPhoneSetting();
        return ActionResult.success(dto);
    }
}
