package com.nexo.model.douyin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.nexo.common.core.domain.R;
import com.nexo.common.core.validate.AddGroup;
import com.nexo.common.core.validate.EditGroup;
import com.nexo.common.core.web.controller.BaseController;
import com.nexo.common.excel.utils.ExcelUtil;
import com.nexo.common.log.annotation.Log;
import com.nexo.common.log.enums.BusinessType;
import com.nexo.common.mybatis.core.page.PageQuery;
import com.nexo.common.mybatis.core.page.TableDataInfo;
import com.nexo.model.douyin.domain.UpdataStatusBo;
import com.nexo.model.douyin.service.INexoDouyinUserInfoService;
import com.nexo.module.api.douyin.domain.NexoDouyinUserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 抖音用户信息控制器
 * 前端访问路由地址为:/douyin/douyinUserInfo
 *
 * @author nexo
 * @date 2026-05-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/douyin/userInfo")
public class NexoDouyinUserInfoController extends BaseController {

    private final INexoDouyinUserInfoService iNexoDouyinUserInfoService;

    /**
     * 查询抖音用户信息列表
     */
    @SaCheckPermission("douyin:douyinUserInfo:list")
    @GetMapping("/list")
    public TableDataInfo<NexoDouyinUserInfo> list(NexoDouyinUserInfo item, PageQuery pageQuery) {
        return iNexoDouyinUserInfoService.queryPageList(item, pageQuery);
    }

    /**
     * 导出抖音用户信息列表
     */
    @SaCheckPermission("douyin:douyinUserInfo:export")
    @Log(title = "抖音用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NexoDouyinUserInfo item, HttpServletResponse response) {
        List<NexoDouyinUserInfo> list = iNexoDouyinUserInfoService.queryList(item);
        ExcelUtil.exportExcel(list, "抖音用户信息", NexoDouyinUserInfo.class, response);
    }

    /**
     * 获取抖音用户信息详细信息
     *
     * @param userId 主键
     */
    @SaCheckPermission("douyin:douyinUserInfo:query")
    @GetMapping("/{userId}")
    public R<NexoDouyinUserInfo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String userId) {
        return R.ok(iNexoDouyinUserInfoService.queryById(userId));
    }

    /**
     * 新增抖音用户信息
     */
    @SaCheckPermission("douyin:douyinUserInfo:add")
    @Log(title = "抖音用户信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NexoDouyinUserInfo item) {
        return toAjax(iNexoDouyinUserInfoService.insertBy(item));
    }

    /**
     * 修改抖音用户信息
     */
    @SaCheckPermission("douyin:douyinUserInfo:edit")
    @Log(title = "抖音用户信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NexoDouyinUserInfo item) {
        return toAjax(iNexoDouyinUserInfoService.updateBy(item));
    }

    /**
     * 删除抖音用户信息
     *
     * @param userIds 主键串
     */
    @SaCheckPermission("douyin:douyinUserInfo:remove")
    @Log(title = "抖音用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] userIds) {
        return toAjax(iNexoDouyinUserInfoService.deleteWithValidByIds(Arrays.asList(userIds), true));
    }

    @PostMapping("/updateMonitorState")
    public R<Void> updateMonitorState(@RequestBody UpdataStatusBo item) {
        return toAjax(iNexoDouyinUserInfoService.updateMonitorState(item));
    }

}
