package jnpf.certificate.controller;

import jnpf.base.ActionResult;
import jnpf.certificate.CertificateManageApi;
import jnpf.certificate.service.CertificateManageApiService;
import jnpf.model.certificate.vo.CertificateOrganizeBusinessLicenseVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

/**
 * 组织营业执照管理接口。
 */
@Validated
@RestController
@RequestMapping("/web/certificate-manage-api")
public class CertificateManageApiController implements CertificateManageApi {

    @Autowired
    private CertificateManageApiService certificateManageApiService;

    @Override
    @GetMapping("/query-business-license")
    public ActionResult<CertificateOrganizeBusinessLicenseVO> queryBusinessLicense(@RequestParam("organizeId") String organizeId) {
        return ActionResult.success(certificateManageApiService.queryBusinessLicense(organizeId));
    }

    @Override
    @PostMapping("/query-business-license-batch")
    public ActionResult<List<CertificateOrganizeBusinessLicenseVO>> queryBusinessLicenseBatch(@RequestBody Collection<String> organizeIds) {
        return ActionResult.success(certificateManageApiService.queryBusinessLicenseBatch(organizeIds));
    }

    @Override
    @PostMapping("/save-business-license")
    public ActionResult<Void> saveBusinessLicense(@Valid @RequestBody CertificateOrganizeBusinessLicenseVO req) {
        certificateManageApiService.saveBusinessLicense(req);
        return ActionResult.success();
    }

    @Override
    @DeleteMapping("/delete-business-license")
    public ActionResult<Void> deleteBusinessLicense(@RequestParam("organizeId") String organizeId,
                                                    @RequestParam(value = "loginUserId", required = false) String loginUserId) {
        certificateManageApiService.deleteBusinessLicense(organizeId, loginUserId);
        return ActionResult.success();
    }
}
