package org.wfc.system.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.common.log.annotation.Log;
import org.wfc.common.log.enums.BusinessType;
import org.wfc.system.domain.UKyc;
import org.wfc.system.domain.bo.UKycUserBo;
import org.wfc.system.domain.constant.KycStatusEnum;
import org.wfc.system.domain.vo.UKycUserVo;
import org.wfc.system.service.IUKycService;

import java.util.List;

/**
 * <p>
 * System Portal-User KYC table contorller
 * </p>
 *
 * @since 2025-01-08
 */
@RestController
@RequestMapping("/kyc")
public class UKycController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(UKycController.class);

    @Autowired
    private IUKycService uKycService;

    @GetMapping("/page")
    public TableDataInfo selectKycByUserId(UKycUserBo item) {
        log.debug("item: {}", item);
        startPage();
        List<UKycUserVo> list = uKycService.selectKycByUserId(item);
        return getDataTable(list);
    }

    @GetMapping("/list")
    public AjaxResult list(UKycUserBo item) {
        startPage();
        List<UKycUserVo> list = uKycService.selectKycByUserId(item);
        return success(list);
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getById(@PathVariable("id") Long id) {
        return success(uKycService.getById(id));
    }

    @Log(title = "menu.user.kyc.management", businessType = BusinessType.APPROVAL)
    @PutMapping("/approve")
    public AjaxResult approve(@RequestBody UKyc uKyc) {
        // set user kyc status to verified
        uKyc.setStatus(KycStatusEnum.VERIFIED.getCode());
        log.debug("uKyc: {}", uKyc);      
        return toAjax(uKycService.updateKycByUserId(uKyc));
    }

    @Log(title = "menu.user.kyc.management", businessType = BusinessType.REJECT)    
    @PutMapping("/reject")
    public AjaxResult reject(@RequestBody UKyc uKyc) {
        // set kyc request status to rejected and put the description in the database
        uKyc.setStatus(KycStatusEnum.REJECTED.getCode());
        uKyc.setDescription(uKyc.getDescription());
        return toAjax(uKycService.updateKycByUserId(uKyc));
    }

    // @DeleteMapping("/{ids}")
    // public AjaxResult remove(@PathVariable Long[] ids) {
    //     return toAjax(uKycService.removeByIds(CollUtil.newArrayList(ids)));
    // }

}
