package com.jwipc.tender.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.tender.constant.ModuleConst;
import com.jwipc.tender.dto.SecurityDepositAccountBaseDTO;
import com.jwipc.tender.logic.SecurityDepositAccountLogic;
import com.jwipc.tender.model.query.BidQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>保证金账号 管理相关页面</p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping(ModuleConst.MODULE_ROOT + "/securityDeposit/rest")
public class SecurityDepositRestController {
    private final SecurityDepositAccountLogic securityDepositAccountLogic;

    /**
     * 保证金账号全部数据
     *
     * @return
     */
    @GetMapping("listAll")
    public ResponseEntity listAll() {
        return ResponseEntity.ok(securityDepositAccountLogic.getListAll());
    }

    /**
     * 保证金账号 新增和编辑数据
     *
     * @param id 账号主键
     * @return
     */
    @GetMapping("detail")
    public ResponseEntity detail(@RequestParam(required = false, defaultValue = "0") Long id)
    {
        return ResponseEntity.ok(securityDepositAccountLogic.getDetail(id));
    }

    /**
     * 保证金账号 新增和编辑接口
     *
     * @param securityDepositAccountBaseDTO 数据对象
     * @return
     */
    @PostMapping("saveOrUpdate")
    public ResponseEntity saveOrUpdate(@RequestBody SecurityDepositAccountBaseDTO securityDepositAccountBaseDTO)
    {
        securityDepositAccountLogic.saveOrUpdate(securityDepositAccountBaseDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 保证金账号全部数据
     *
     * @return
     */
    @GetMapping("approvelList")
    public PageView approvelList(BidQuery bidQuery) {
        return securityDepositAccountLogic.getApprovelList(bidQuery);
    }

    @PostMapping("updateDepositStatus")
    public ResponseEntity updateDepositStatus(String ids, Integer status,String reason) {
        securityDepositAccountLogic.updateDepositStatus(ids, status,reason);
        return ResponseEntity.ok().build();
    }

    @PostMapping("updateMarginStatus")
    public ResponseEntity updateMarginStatus(String ids, Integer status) {
        securityDepositAccountLogic.updateMarginStatus(ids, status);
        return ResponseEntity.ok().build();
    }
}
