package com.jwipc.supplier.controller.pc;

import com.jwipc.constant.EnableStatus;
import com.jwipc.page.PageView;
import com.jwipc.supplier.dto.QualificationBaseDTO;
import com.jwipc.supplier.dto.QualificationTemplateBaseDTO;
import com.jwipc.supplier.dto.QualificationTemplateSaveDTO;
import com.jwipc.supplier.logic.QualificationLogic;
import com.jwipc.supplier.model.query.QualificationQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.jwipc.supplier.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> 资质配置接口</p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping(MODULE_ROOT + "/qualification/rest")
@RequiredArgsConstructor
@Slf4j
public class QualificationRestController {
    private final QualificationLogic qualificationLogic;

    /**
     * 资质配置项 分页列表接口
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping("list")
    public PageView list(QualificationQuery query) {
        PageView pageView = qualificationLogic.getList(query);
        return pageView;
    }

    /**
     * 资质配置项 编辑和保存接口
     *
     * @param qualificationBaseDTO 保存对象
     * @return
     */
    @PostMapping("saveOrUpdate")
    public ResponseEntity saveOrUpdate(QualificationBaseDTO qualificationBaseDTO) {
        qualificationLogic.saveOrUpdate(qualificationBaseDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 资质配置项状态更新
     *
     * @param id    资质配置 主键
     * @param state 状态值 枚举请看 EnableStatus
     * @return
     * @see EnableStatus
     */
    @PostMapping("updateState")
    public ResponseEntity updateState(Long id, Integer state) {
        qualificationLogic.updateState(id, state);
        return ResponseEntity.ok().build();
    }

    /**
     * 资质模板分页列表
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping("template/list")
    public PageView templateList(QualificationQuery query) {
        PageView pageView = qualificationLogic.getTemplateList(query);
        return pageView;
    }


    /**
     * 资质模板全部数据接口
     *
     * @param query 查询参数
     * @return
     */
    @GetMapping("template/listAll")
    public ResponseEntity<List<QualificationTemplateBaseDTO>> templateListAll(QualificationQuery query) {
        return ResponseEntity.ok(qualificationLogic.getTemplateListAll(query));
    }

    /**
     * 更新资质模板状态
     *
     * @param id    资质模板主键
     * @param state 状态 枚举请看 EnableStatus
     * @return
     * @see EnableStatus
     */
    @PostMapping("template/updateState")
    public ResponseEntity templateUpdateState(Long id, Integer state) {
        qualificationLogic.templateUpdateState(id, state);
        return ResponseEntity.ok().build();
    }

    /**
     * 资质模板中-资质配置项列表
     *
     * @param templateId 资质模板的主键
     * @return
     */
    @GetMapping("template/item/list")
    public PageView templateItemList(Long templateId) {
        PageView pageView = qualificationLogic.getTemplateItemListByTemplateId(templateId);
        return pageView;
    }

    /**
     * 资质模板中-资质配置项列表
     *
     * @param templateCode 资质模板的编号
     * @param version      资质模板版本
     * @return
     */
    @GetMapping("template/item/listByTemplateCode")
    public ResponseEntity templateItemListByTemplateCode(String templateCode, String version) {
        return ResponseEntity.ok(qualificationLogic.getTemplateItemListByTemplateCode(templateCode, version));
    }

    /**
     * 资质模板新增和修改保存接口
     *
     * @param qualificationTemplateSaveDTO 保存参数
     * @return
     */
    @PostMapping("template/saveOrUpdate")
    public ResponseEntity templateSaveOrUpdate(@RequestBody QualificationTemplateSaveDTO qualificationTemplateSaveDTO) {
        qualificationLogic.templateSaveOrUpdate(qualificationTemplateSaveDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询供应商的资质项
     *
     * @param supplierId 供应商编码
     * @return
     */
    @GetMapping("supplierQualifications")
    public ResponseEntity supplierQualifications(Long supplierId,String typeStr,String codes) {
        return ResponseEntity.ok(qualificationLogic.getSupplierQualifications(supplierId,typeStr,codes));
    }
}
