package org.dromara.payment.worker.controller;

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.payment.worker.domain.vo.UserWorkerAccountVo;
import org.dromara.payment.worker.domain.bo.UserWorkerAccountBo;
import org.dromara.payment.worker.service.IUserWorkerAccountService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 自雇者账户
 * 前端访问路由地址为:/payment/workerAccount
 *
 * @author LionLi
 * @date 2024-04-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workerAccount")
public class UserWorkerAccountController extends BaseController {

    private final IUserWorkerAccountService userWorkerAccountService;

    /**
     * 查询自雇者账户列表
     */
//    @SaCheckPermission("payment:workerAccount:list")
    @GetMapping("/list")
    public TableDataInfo<UserWorkerAccountVo> list(UserWorkerAccountBo bo, PageQuery pageQuery) {
        return userWorkerAccountService.queryPageList(bo, pageQuery);
    }



    /**
     * 查询自雇者账户列表
     */
//    @SaCheckPermission("payment:workerAccount:bankList")
    @GetMapping("/bankList")
    public R bankList(UserWorkerAccountBo bo) {
        return R.ok(userWorkerAccountService.queryList(bo));
    }




    /**
     * 导出自雇者账户列表
     */
    @SaCheckPermission("payment:workerAccount:export")
    @Log(title = "自雇者账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(UserWorkerAccountBo bo, HttpServletResponse response) {
        List<UserWorkerAccountVo> list = userWorkerAccountService.queryList(bo);
        ExcelUtil.exportExcel(list, "自雇者账户", UserWorkerAccountVo.class, response);
    }

    /**
     * 获取自雇者账户详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("payment:workerAccount:query")
    @GetMapping("/{id}")
    public R<UserWorkerAccountVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userWorkerAccountService.queryById(id));
    }

    /**
     * 新增自雇者账户
     */
//    @SaCheckPermission("payment:workerAccount:add")
    @Log(title = "自雇者账户", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserWorkerAccountBo bo) {
        return toAjax(userWorkerAccountService.insertByBo(bo));
    }

    /**
     * 修改自雇者账户
     */
//    @SaCheckPermission("payment:workerAccount:edit")
    @Log(title = "自雇者账户", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserWorkerAccountBo bo) {
        return toAjax(userWorkerAccountService.updateByBo(bo));
    }

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