package com.spring.controller;

import com.spring.domain.dto.UserLoginDto;
import com.spring.domain.entity.UserLoginEntity;
import com.spring.domain.vo.UserLoginVo;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import com.spring.service.UserLoginService;
import com.spring.domain.vo.result.PageResult;
import com.spring.domain.vo.result.Result;
import com.spring.domain.vo.result.ResultCodeEnum;
import java.util.List;

/**
 * <p>
 * 用户登录日志 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-10 12:02:29
 */
@Tag(name = "用户登录日志", description = "用户登录日志相关接口")
@RestController
@RequestMapping("/api/product/user-login")
@RequiredArgsConstructor
public class UserLoginController {

    private final UserLoginService userLoginService;

    @Operation(summary = "分页查询用户登录日志", description = "分页用户登录日志")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<UserLoginVo>> getUserLoginPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            UserLoginDto dto) {
        Page<UserLoginEntity> pageParams = new Page<>(page, limit);
        PageResult<UserLoginVo> pageResult = userLoginService.getUserLoginPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加用户登录日志", description = "添加用户登录日志")
    @PostMapping()
    public Result<String> addUserLogin(@Valid @RequestBody UserLoginDto dto) {
            userLoginService.addUserLogin(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新用户登录日志", description = "更新用户登录日志")
    @PutMapping()
    public Result<String> updateUserLogin(@Valid @RequestBody UserLoginDto dto) {
            userLoginService.updateUserLogin(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除用户登录日志", description = "删除用户登录日志")
    @DeleteMapping()
    public Result<String> deleteUserLogin(@RequestBody List<Long> ids) {
            userLoginService.deleteUserLogin(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}