package shop.alien.store.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.dto.AccountLogoutCompleteRequestDTO;
import shop.alien.entity.store.vo.AccountLogoutCompleteResultVo;
import shop.alien.store.service.AccountLogoutCompleteService;

/**
 * 注销冷静期测试接口（仅启动 alien-store 即可联调，跳过 7 天等待）
 */
@Slf4j
@Api(tags = "账号注销-测试")
@RestController
@RequestMapping("/account/logout/test")
@RequiredArgsConstructor
public class AccountLogoutTestController {

    private final AccountLogoutCompleteService accountLogoutCompleteService;

    @ApiOperation(value = "强制完成注销冷静期", notes = "默认跳过7天校验，立即将冷静期账号变为已注销。accountType: ALL|STORE_USER|LIFE_USER|LAWYER|STORE；可传 id 或 phone 指定单条")
    @PostMapping("/force-complete-cooling")
    public R<AccountLogoutCompleteResultVo> forceCompleteCooling(
            @RequestBody(required = false) AccountLogoutCompleteRequestDTO request) {
        if (request == null) {
            request = new AccountLogoutCompleteRequestDTO();
        }
        request.setForce(true);
        log.info("AccountLogoutTestController.forceCompleteCooling request={}", request);
        AccountLogoutCompleteResultVo result = accountLogoutCompleteService.completeCoolingPeriod(request);
        return R.data(result);
    }

    @ApiOperation("强制完成全部冷静期账号（GET 快捷调用）")
    @GetMapping("/force-complete-cooling")
    public R<AccountLogoutCompleteResultVo> forceCompleteCoolingGet(
            @RequestParam(required = false) String accountType,
            @RequestParam(required = false) Integer id,
            @RequestParam(required = false) String phone) {
        AccountLogoutCompleteRequestDTO request = new AccountLogoutCompleteRequestDTO();
        request.setAccountType(accountType);
        request.setId(id);
        request.setPhone(phone);
        request.setForce(true);
        log.info("AccountLogoutTestController.forceCompleteCoolingGet request={}", request);
        return R.data(accountLogoutCompleteService.completeCoolingPeriod(request));
    }
}
