package org.dromara.talk.controller.admin;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.talk.domain.vo.PhoneUserVo;
import org.dromara.talk.domain.bo.PhoneUserBo;
import org.dromara.talk.service.IPhoneUserService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * ZoomPhone用户管理
 *
 * @author Lion Li
 * @date 2026-02-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/talk/admin/zoomphone/user")
public class PhoneUserController extends BaseController {

    private final IPhoneUserService phoneUserService;

    /**
     * 查询ZoomPhone用户列表
     */
    @SaCheckPermission("zoomphone:user:list")
    @GetMapping("/list")
    public TableDataInfo<PhoneUserVo> list(PhoneUserBo bo, PageQuery pageQuery) {
        return phoneUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出ZoomPhone用户列表
     */
    @SaCheckPermission("zoomphone:user:export")
    @Log(title = "ZoomPhone用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PhoneUserBo bo, HttpServletResponse response) {
        List<PhoneUserVo> list = phoneUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "ZoomPhone用户", PhoneUserVo.class, response);
    }

    /**
     * 获取ZoomPhone用户详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("zoomphone:user:query")
    @GetMapping("/{id}")
    public R<PhoneUserVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(phoneUserService.queryById(id));
    }

    /**
     * 新增ZoomPhone用户
     */
    @SaCheckPermission("zoomphone:user:add")
    @Log(title = "ZoomPhone用户", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PhoneUserBo bo) {
        return toAjax(phoneUserService.insertByBo(bo));
    }

    /**
     * 修改ZoomPhone用户
     */
    @SaCheckPermission("zoomphone:user:edit")
    @Log(title = "ZoomPhone用户", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PhoneUserBo bo) {
        return toAjax(phoneUserService.updateByBo(bo));
    }

    /**
     * 删除ZoomPhone用户
     *
     * @param ids 主键串
     */
    @SaCheckPermission("zoomphone:user:remove")
    @Log(title = "ZoomPhone用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(phoneUserService.deleteWithValidByIds(List.of(ids), true));
    }
}
