package com.mall.member.controller;

import com.mall.member.domain.dto.MemberLoginLogDto;
import com.mall.member.domain.entity.MemberLoginLog;
import com.mall.member.domain.vo.MemberLoginLogVo;
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.mall.member.service.MemberLoginLogService;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;

import java.util.List;

/**
 * <p>
 * 会员登录记录 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 19:30:06
 */
@Tag(name = "会员登录记录", description = "会员登录记录相关接口")
@RestController
@RequestMapping("/api/member/member-login-log")
@RequiredArgsConstructor
public class MemberLoginLogController {

    private final MemberLoginLogService memberLoginLogService;

    @Operation(summary = "分页查询会员登录记录", description = "分页会员登录记录")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<MemberLoginLogVo>> getMemberLoginLogPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            MemberLoginLogDto dto) {
        Page<MemberLoginLog> pageParams = new Page<>(page, limit);
        PageResult<MemberLoginLogVo> pageResult = memberLoginLogService.getMemberLoginLogPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加会员登录记录", description = "添加会员登录记录")
    @PostMapping()
    public Result<String> addMemberLoginLog(@Valid @RequestBody MemberLoginLogDto dto) {
            memberLoginLogService.addMemberLoginLog(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新会员登录记录", description = "更新会员登录记录")
    @PutMapping()
    public Result<String> updateMemberLoginLog(@Valid @RequestBody MemberLoginLogDto dto) {
            memberLoginLogService.updateMemberLoginLog(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除会员登录记录", description = "删除会员登录记录")
    @DeleteMapping()
    public Result<String> deleteMemberLoginLog(@RequestBody List<Long> ids) {
            memberLoginLogService.deleteMemberLoginLog(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}