package com.crm.manager.controller;

import com.crm.manager.service.MarketPromoCodeEmailFeignService;
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.market.MarketEmailStatusNumberDto;
import com.crm.rely.backend.core.dto.market.promo.code.email.MarketPromoCodeEmailListDto;
import com.crm.rely.backend.core.dto.market.promo.code.email.record.MarketPromoCodeEmailRecordListDto;
import com.crm.rely.backend.core.dto.market.upload.email.MarketUploadEmailListDto;
import com.crm.rely.backend.core.dto.system.email.template.SysEmailTemplateSearchDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.market.promo.code.email.MarketPromoCodeEmailAddEntity;
import com.crm.rely.backend.core.entity.market.promo.code.email.MarketPromoCodeEmailSearchPageEntity;
import com.crm.rely.backend.core.entity.market.promo.code.email.record.MarketPromoCodeEmailRecordSearchPageEntity;
import com.crm.rely.backend.core.entity.market.promo.code.email.record.MarketPromoCodeEmailRecordSendEntity;
import com.crm.rely.backend.core.entity.market.promo.code.email.record.MarketPromoCodeEmailRecordStatusNumberEntity;
import com.crm.rely.backend.core.entity.market.promo.code.email.record.MarketPromoCodeRecordSupplementSendEntity;
import com.crm.rely.backend.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 营销群发邮件
 *
 * @author houn
 */
@RestController
@RequestMapping("/market/promo/code/email")
public class MarketPromoCodeEmailController {

    @Autowired
    private MarketPromoCodeEmailFeignService marketPromoCodeEmailFeignService;


    /**
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated MarketPromoCodeEmailAddEntity entity) throws Exception {
        return marketPromoCodeEmailFeignService.add(entity);
    }

    @PostMapping("/add/email/template")
    public BaseResultDto<List<SysEmailTemplateSearchDto>> getEmailTemplate() throws Exception {
        return marketPromoCodeEmailFeignService.getEmailTemplate();
    }

    @PostMapping("/add/upload/email")
    public BaseResultDto<List<MarketUploadEmailListDto>> getUploadEmialList() throws Exception {
        return marketPromoCodeEmailFeignService.getUploadEmialList();
    }

    @PostMapping("/send/email")
    public BaseResultDto send(@RequestBody @Validated MarketPromoCodeEmailRecordSendEntity entity) throws ServiceException {
        return marketPromoCodeEmailFeignService.send(entity);
    }

    @PostMapping("/search/list")
    public ResultWithPagerDto<MarketPromoCodeEmailListDto> pageList(@RequestBody @Validated MarketPromoCodeEmailSearchPageEntity entity) throws Exception {
        return marketPromoCodeEmailFeignService.pageList(entity);
    }

    @PostMapping("/search/single")
    public BaseResultDto<MarketPromoCodeEmailListDto> single(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        return marketPromoCodeEmailFeignService.single(entity);
    }

    /**
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/list/record")
    public ResultWithPagerDto<MarketPromoCodeEmailRecordListDto> pageListRecord(@RequestBody @Validated MarketPromoCodeEmailRecordSearchPageEntity entity) throws Exception {
        return marketPromoCodeEmailFeignService.pageListRecord(entity);
    }

    @PostMapping("/search/list/record/status/number")
    public BaseResultDto<MarketEmailStatusNumberDto> statusNumber(@RequestBody @Validated MarketPromoCodeEmailRecordStatusNumberEntity entity) throws Exception {
        return marketPromoCodeEmailFeignService.statusNumber(entity);
    }

    @PostMapping("/supplement/send")
    public BaseResultDto supplementSend(@RequestBody @Validated SingleLongEntity entity) throws Exception {

        return marketPromoCodeEmailFeignService.supplementSend(entity);
    }

    @PostMapping("/supplement/send/batch")
    public BaseResultDto supplementSend(@RequestBody @Validated MarketPromoCodeRecordSupplementSendEntity entity) throws Exception {

        return marketPromoCodeEmailFeignService.supplementSend(entity);
    }

    @PostMapping("/add/upload")
    public BaseResultDto upload(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
        return marketPromoCodeEmailFeignService.upload(file);
    }
}
