package com.zsElectric.boot.business.controller;

import com.zsElectric.boot.business.service.UserInfoIntegralLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zsElectric.boot.business.model.form.UserInfoIntegralLogForm;
import com.zsElectric.boot.business.model.query.UserInfoIntegralLogQuery;
import com.zsElectric.boot.business.model.vo.UserInfoIntegralLogVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zsElectric.boot.core.web.PageResult;
import com.zsElectric.boot.core.web.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 用户积分日志记录前端控制层
 *
 * @author zsElectric
 * @since 2025-12-12 10:25
 */
@Tag(name = "用户积分日志记录接口")
@RestController
@RequestMapping("/api/v1/user-info-integral-log")
@RequiredArgsConstructor
public class UserInfoIntegralLogController  {

    private final UserInfoIntegralLogService userInfoIntegralLogService;

    @Operation(summary = "用户积分日志记录分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('business:user-info-integral-log:query')")
    public PageResult<UserInfoIntegralLogVO> getUserInfoIntegralLogPage(UserInfoIntegralLogQuery queryParams ) {
        IPage<UserInfoIntegralLogVO> result = userInfoIntegralLogService.getUserInfoIntegralLogPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增用户积分日志记录")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('business:user-info-integral-log:add')")
    public Result<Void> saveUserInfoIntegralLog(@RequestBody @Valid UserInfoIntegralLogForm formData ) {
        boolean result = userInfoIntegralLogService.saveUserInfoIntegralLog(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取用户积分日志记录表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('business:user-info-integral-log:edit')")
    public Result<UserInfoIntegralLogForm> getUserInfoIntegralLogForm(
        @Parameter(description = "用户积分日志记录ID") @PathVariable Long id
    ) {
        UserInfoIntegralLogForm formData = userInfoIntegralLogService.getUserInfoIntegralLogFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改用户积分日志记录")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('business:user-info-integral-log:edit')")
    public Result<Void> updateUserInfoIntegralLog(
            @Parameter(description = "用户积分日志记录ID") @PathVariable Long id,
            @RequestBody @Validated UserInfoIntegralLogForm formData
    ) {
        boolean result = userInfoIntegralLogService.updateUserInfoIntegralLog(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除用户积分日志记录")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('business:user-info-integral-log:delete')")
    public Result<Void> deleteUserInfoIntegralLogs(
        @Parameter(description = "用户积分日志记录ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = userInfoIntegralLogService.deleteUserInfoIntegralLogs(ids);
        return Result.judge(result);
    }
}
