package com.jeequan.jeepay.agent.ctrl.payconfig;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeequan.jeepay.agent.ctrl.CommonCtrl;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.db.entity.QualificationDefineEntity;
import com.jeequan.jeepay.service.impl.QualificationDefineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/qualificationDefine")
@RestController
public class QualificationDefineController extends CommonCtrl {

    @Autowired
    private QualificationDefineService qualificationDefineService;

    @PostMapping("/save")
    public ApiRes save() {
        QualificationDefineEntity entity = getObject(QualificationDefineEntity.class);
        boolean save = qualificationDefineService.save(entity);

        return ApiRes.ok(save);
    }

    @GetMapping("/page")
    public ApiRes page() {
        Page<QualificationDefineEntity> iPage = getIPage(false);
        QualificationDefineEntity condition = getObject(QualificationDefineEntity.class);
        qualificationDefineService.lambdaQuery().setEntity(condition).page(iPage);

        return ApiRes.ok(iPage);
    }

    @GetMapping("/{code}")
    public ApiRes one(@PathVariable String code) {
        QualificationDefineEntity one = qualificationDefineService.lambdaQuery().eq(QualificationDefineEntity::getCode, code).one();
        return ApiRes.ok(one);
    }

    @DeleteMapping("/{code}")
    public ApiRes del(@PathVariable String code) {
        qualificationDefineService.removeById(code);
        return ApiRes.ok();
    }
}
