package com.zsElectric.boot.business.controller;

import com.zsElectric.boot.business.service.UserAccountLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zsElectric.boot.business.model.form.UserAccountLogForm;
import com.zsElectric.boot.business.model.query.UserAccountLogQuery;
import com.zsElectric.boot.business.model.vo.UserAccountLogVO;
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:18
 */
@Tag(name = "个人账户变更记录接口")
@RestController
@RequestMapping("/api/v1/user-account-log")
@RequiredArgsConstructor
public class UserAccountLogController  {

    private final UserAccountLogService userAccountLogService;

    @Operation(summary = "个人账户变更记录分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('business:user-account-log:query')")
    public PageResult<UserAccountLogVO> getUserAccountLogPage(UserAccountLogQuery queryParams ) {
        IPage<UserAccountLogVO> result = userAccountLogService.getUserAccountLogPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增个人账户变更记录")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('business:user-account-log:add')")
    public Result<Void> saveUserAccountLog(@RequestBody @Valid UserAccountLogForm formData ) {
        boolean result = userAccountLogService.saveUserAccountLog(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取个人账户变更记录表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('business:user-account-log:edit')")
    public Result<UserAccountLogForm> getUserAccountLogForm(
        @Parameter(description = "个人账户变更记录ID") @PathVariable Long id
    ) {
        UserAccountLogForm formData = userAccountLogService.getUserAccountLogFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改个人账户变更记录")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('business:user-account-log:edit')")
    public Result<Void> updateUserAccountLog(
            @Parameter(description = "个人账户变更记录ID") @PathVariable Long id,
            @RequestBody @Validated UserAccountLogForm formData
    ) {
        boolean result = userAccountLogService.updateUserAccountLog(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除个人账户变更记录")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('business:user-account-log:delete')")
    public Result<Void> deleteUserAccountLogs(
        @Parameter(description = "个人账户变更记录ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = userAccountLogService.deleteUserAccountLogs(ids);
        return Result.judge(result);
    }
}
