package com.crm.manager.controller;

import com.crm.manager.service.activity.CustomActivityPercentageGiveFeignService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.core.dto.custom.activity.percentage.give.CustomActivityPercentageGiveDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.custom.activity.percentage.give.CustomActivityPercentageGiveApproveEntity;
import com.crm.rely.backend.core.entity.custom.activity.percentage.give.CustomActivityPercentageGiveDeleteEntity;
import com.crm.rely.backend.core.entity.custom.activity.percentage.give.CustomActivityPercentageGiveSearchEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.RestController;

/**
 * @author: houn
 */
@RestController
@RequestMapping("/custom/activity/percentage/give")
public class CustomActivityPercentageGiveController {

    @Autowired
    private CustomActivityPercentageGiveFeignService feignService;

    @PostMapping("/approve")
    public BaseResultDto approve(@RequestBody @Validated CustomActivityPercentageGiveApproveEntity entity) throws Exception {
        if (!Constants.PASSED_STATUS.equals(entity.getStatus()) && !Constants.REJECTED_STATUS.equals(entity.getStatus())) {
            return BaseResultDto.error(Constants.NOT_PERMIT);
        }
        feignService.approve(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated CustomActivityPercentageGiveDeleteEntity entity) throws Exception {
        feignService.delete(entity);
        return BaseResultDto.success();
    }


    @PostMapping("/search/list")
    public ResultWithPagerDto<CustomActivityPercentageGiveDto> searcherList(@RequestBody @Validated CustomActivityPercentageGiveSearchEntity entity) throws Exception {

        ResultWithPagerDto<CustomActivityPercentageGiveDto> resultWithPagerDto = feignService.searcherList(entity);
        return resultWithPagerDto;
    }

    @PostMapping("/search/single")
    public BaseResultDto searcherSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        return feignService.searcherSingle(entity);
    }

}
