package com.kexue.skills.controller;

import com.kexue.skills.annotation.Log;
import com.kexue.skills.common.CommonResult;
import com.kexue.skills.entity.AccountFrozen;
import com.kexue.skills.entity.dto.AccountFrozenDto;
import com.kexue.skills.entity.dto.AccountReleaseDto;
import com.kexue.skills.service.AccountFrozenService;
import com.kexue.skills.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 账户冻结单控制器
 *
 * @author 系统生成
 * @since 2026-04-11
 */
@Log(module = "账户冻结")
@RestController
@RequestMapping("/api/accountFrozen")
@CrossOrigin(origins = "*")
@Tag(name = "账户冻结单", description = "账户冻结单管理接口")
public class AccountFrozenController {

    private static final Logger logger = LoggerFactory.getLogger(AccountFrozenController.class);
    private static final ObjectMapper objectMapper = new ObjectMapper();

    @Resource
    private AccountFrozenService accountFrozenService;

    /**
     * 创建冻结单
     * @param accountFrozenDto 冻结单DTO
     * @return 冻结单信息
     */
    @PostMapping("/frozen")
    @Operation(summary = "创建冻结单", description = "创建账户冻结单")
    public CommonResult<AccountFrozen> createFrozen(@RequestBody AccountFrozenDto accountFrozenDto) {
        try {
            logger.info("创建冻结单入参: {}", objectMapper.writeValueAsString(accountFrozenDto));
        } catch (IOException e) {
            logger.error("创建冻结单入参序列化失败", e);
        }
        AccountFrozen accountFrozen = accountFrozenService.createFrozen(accountFrozenDto);
        return CommonResult.success(accountFrozen);
    }

    /**
     * 释放冻结单
     * @param accountReleaseDto 冻结单释放DTO
     * @return 冻结单信息
     */
    @PostMapping("/release")
    @Operation(summary = "释放冻结单", description = "释放账户冻结单")
    public CommonResult<AccountFrozen> releaseFrozen(@RequestBody AccountReleaseDto accountReleaseDto) {
        try {
            logger.info("释放冻结单入参: {}", objectMapper.writeValueAsString(accountReleaseDto));
        } catch (IOException e) {
            logger.error("释放冻结单入参序列化失败", e);
        }
        AccountFrozen accountFrozen = accountFrozenService.releaseFrozen(accountReleaseDto);
        return CommonResult.success(accountFrozen);
    }

}
