package com.crm.email.controller;

import com.crm.email.service.SysEmailUnsubscribeService;
import com.crm.rely.backend.core.constant.FeignClientAnnotation;
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.system.email.unsubscribe.SysEmailUnsubscribeSearchDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.system.email.unsubscribe.SysEmailUnsubscribeAddEntity;
import com.crm.rely.backend.core.entity.system.email.unsubscribe.SysEmailUnsubscribeDeleteEntity;
import com.crm.rely.backend.core.entity.system.email.unsubscribe.SysEmailUnsubscribeRequestEntity;
import com.crm.rely.backend.core.entity.system.email.unsubscribe.SysEmailUnsubscribeSearchListEntity;
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;

import javax.annotation.Resource;

@RestController
@RequestMapping("/email/unsubscribe")
public class EmailUnsubscribeController {

    @Resource
    private SysEmailUnsubscribeService sysEmailUnsubscribeService;

    /**
     * 添加退订
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/manager/add")
    @FeignClientAnnotation
    public BaseResultDto managerAdd(@RequestBody SysEmailUnsubscribeAddEntity entity) throws Exception {
        sysEmailUnsubscribeService.add(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/custom/add")
    @FeignClientAnnotation
    public BaseResultDto customAdd(@RequestBody SysEmailUnsubscribeRequestEntity entity) throws Exception {
        sysEmailUnsubscribeService.add(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/manager/delete")
    @FeignClientAnnotation
    public BaseResultDto delete(@RequestBody SysEmailUnsubscribeDeleteEntity entity) throws Exception {

        sysEmailUnsubscribeService.delete(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/manager/search/list")
    @FeignClientAnnotation
    public ResultWithPagerDto<SysEmailUnsubscribeSearchDto> searchList(@RequestBody @Validated SysEmailUnsubscribeSearchListEntity entity) throws Exception {

        return sysEmailUnsubscribeService.searchPageList(entity);
    }

    @PostMapping("/manager/search/single")
    @FeignClientAnnotation
    public BaseResultDto<SysEmailUnsubscribeSearchDto> searchSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        SysEmailUnsubscribeSearchDto sysEmailUnsubscribeSearchDto = sysEmailUnsubscribeService.searchSingle(entity);
        return BaseResultDto.success(sysEmailUnsubscribeSearchDto);
    }

}

