package com.jwipc.supplier.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.supplier.dto.SupplierBankDTO;
import com.jwipc.supplier.dto.SupplierInvitationSaveDTO;
import com.jwipc.supplier.logic.SupplierInvitationLogic;
import com.jwipc.supplier.model.query.SupplierInvitationQuery;
import lombok.RequiredArgsConstructor;
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 + "/invitation/rest")
@RequiredArgsConstructor
public class SupplierInvitationRestController {
    private final SupplierInvitationLogic invitationLogic;

    @GetMapping("list")
    public PageView list(SupplierInvitationQuery query) {
        return invitationLogic.getList(query);
    }

    @PostMapping("/find/list")
    public ResponseEntity<?> findSupplierInvitationData(Long supplierId) {
        List<SupplierInvitationSaveDTO> dtoList = invitationLogic.getListSupplierInvitation(supplierId);
        return ResponseEntity.ok(dtoList);
    }

    @PostMapping("saveOrUpdate")
    public ResponseEntity saveOrUpdate(@RequestBody SupplierInvitationSaveDTO supplierInvitationSaveDTO) {
        invitationLogic.saveOrUpdate(supplierInvitationSaveDTO);
        return ResponseEntity.ok().build();
    }

    @PostMapping("updateReview")
    public ResponseEntity updateReview( Long id, String assessType,String specialRemark ) {
        invitationLogic.updateReviewMethod(id,assessType,specialRemark);
        return ResponseEntity.ok().build();
    }

    @GetMapping("generateUrl")
    public ResponseEntity generateUrl(Long supplierId, Long templateId) {
        return ResponseEntity.ok(invitationLogic.generateUrl(supplierId, templateId));
    }

    @PostMapping("remove")
    public ResponseEntity remove(Long id) {
        invitationLogic.remove(id);
        return ResponseEntity.ok().build();
    }

    @PostMapping("forceRemove")
    public ResponseEntity forceRemove(Long id) {
        invitationLogic.forceRemove(id);
        return ResponseEntity.ok().build();
    }

    @PostMapping("updateTemplate")
    public ResponseEntity updateTemplate(Long id, Long templateId) {
        invitationLogic.updateTemplate(id, templateId);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商邀请通过
     *
     * @param id
     * @param remark
     * @return
     */
    @PostMapping("agree")
    public ResponseEntity agree(Long id, String remark) {
        invitationLogic.agree(id, remark);
        return ResponseEntity.ok().build();
    }

    /**
     * 供应商邀请驳回
     *
     * @param id
     * @param remark
     * @return
     */
    @PostMapping("reject")
    public ResponseEntity reject(Long id, String remark) {
        invitationLogic.reject(id, remark);
        return ResponseEntity.ok().build();
    }

    @PostMapping("sendEmail")
    public ResponseEntity sendEmail(Long id) {
        invitationLogic.sendEmail(id);
        return ResponseEntity.ok().build();
    }

    @GetMapping("updateState")
    public ResponseEntity updateState(@RequestParam Long id) {
        invitationLogic.updateState(id);
        return ResponseEntity.ok().build();
    }
}
