package com.ningdatech.carapi.company.controller;

import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ningdatech.carapi.company.entity.NdCompanyCreditReward;
import com.ningdatech.carapi.company.entity.dto.CompanyCreditRewardPageParam;
import com.ningdatech.carapi.company.service.INdCompanyCreditRewardService;
import com.ningdatech.carapi.sys.entity.dto.CompanyDTO;
import com.ningdatech.carapi.sys.helper.CompaniesCacheHelper;
import com.ningdatech.carapi.sys.helper.RegionsCacheHelper;

import lombok.RequiredArgsConstructor;


/**
 * <p>
 * 政府/行业嘉奖 前端控制器
 * </p>
 *
 * @author liushuai
 * @since 2022-10-10
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/company-credit-reward")
public class NdCompanyCreditRewardController {
    private final INdCompanyCreditRewardService iNdCompanyCreditRewardService;
    private final RegionsCacheHelper regionsCacheHelper;
    private final CompaniesCacheHelper companiesCacheHelper;

    @PostMapping
    private Boolean saveCreditReward(@RequestBody NdCompanyCreditReward ndCompanyCreditReward) {
        CompanyDTO company = companiesCacheHelper.getById(ndCompanyCreditReward.getCompanyId());
        if (0 != company.getRegionId() && null != company.getRegionId()){
            ndCompanyCreditReward.setRegionName(regionsCacheHelper.getDisplayName(company.getRegionId()));
        }
        return iNdCompanyCreditRewardService.save(ndCompanyCreditReward);
    }

    @GetMapping
    private Page<NdCompanyCreditReward> getCreditRewardList(@ModelAttribute CompanyCreditRewardPageParam param) {
        return iNdCompanyCreditRewardService.getCreditRewardList(param);
    }

    @PutMapping
    private Boolean updateCreditReward(@RequestBody NdCompanyCreditReward ndCompanyCreditReward) {
        return iNdCompanyCreditRewardService.updateById(ndCompanyCreditReward);
    }

    @DeleteMapping
    private Boolean deleteCreditReward(@RequestBody NdCompanyCreditReward ndCompanyCreditReward) {
        return iNdCompanyCreditRewardService.delete(ndCompanyCreditReward.getId());
    }

}
