package com.hr.controller;

import com.github.pagehelper.PageInfo;
import com.hr.param.IpAccountParam;
import com.hr.param.SwitchStatusParam;
import com.hr.service.IpAccountService;
import com.hr.vo.IpAccountVO;
import com.yy.basedevelop.common.data.BasePageResult;
import com.yy.basedevelop.common.data.BaseReturnDto;
import com.yy.basedevelop.common.http.config.TokenUtil;
import com.yy.basedevelop.dto.LoginUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

/**
 * 账户管理
 * @author : longhoo
 * @date : 2025-10-10
 */
@RestController
@RequestMapping("/ipAccount")
@Tag(name = "账户管理")
public class IpAccountController{
    @Autowired
    private IpAccountService ipAccountService;
    
    /** 
     * 分页查询
     *
     * @param ipAccountParam 筛选条件
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @GetMapping("/list")
    public Mono<BasePageResult<IpAccountVO>> paginQuery(IpAccountParam ipAccountParam){
        BasePageResult<IpAccountVO> ipAccountPOS = ipAccountService.paginQuery(ipAccountParam, ipAccountParam.getPageNum(), ipAccountParam.getPageSize());
        return Mono.just(ipAccountPOS);
    }
    
    /** 
     * 新增数据
     *
     * @param accountParam 实例对象
     * @return 实例对象
     */
    @Operation(summary = "新增/更新数据")
    @PostMapping("/saveOrUpdate")
    public Mono<BaseReturnDto<IpAccountVO>> saveOrUpdate(@RequestBody IpAccountParam accountParam){
        LoginUser user= TokenUtil.getUser();
        ipAccountService.saveOrUpdate(accountParam,user.getUsername(),user.getUserid());
        return Mono.just(BaseReturnDto.success());
    }

    /** 
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Operation(summary = "通过主键删除数据")
    @DeleteMapping("/delete/{id}")
    public Mono<BaseReturnDto<Boolean>> deleteById(@PathVariable Long id){
        LoginUser user = TokenUtil.getUser();
        return Mono.just(BaseReturnDto.success(ipAccountService.deleteById(id,user)));
    }

    /**
     * 修改状态
     *
     * @param switchStatusParam 主键
     * @return 是否成功
     */
    @Operation(summary = "修改状态")
    @PostMapping("/switchStatus")
    public Mono<BaseReturnDto<Boolean>> switchStatus(@RequestBody SwitchStatusParam switchStatusParam){
        LoginUser user = TokenUtil.getUser();
        return Mono.just(BaseReturnDto.success(ipAccountService.switchStatus(switchStatusParam,user)));
    }
}