package com.crm.manager.controller;

import com.crm.login.rely.backend.controller.BaseLoginController;
import com.crm.manager.service.CommonService;
import com.crm.manager.service.activity.WebLiveInformationFeignService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.web.live.WebLiveInformationAddEntity;
import com.crm.rely.backend.core.entity.web.live.WebLiveInformationDeleteEntity;
import com.crm.rely.backend.core.entity.web.live.WebLiveInformationSearchListEntity;
import com.crm.rely.backend.core.entity.web.live.WebLiveInformationUpdateEntity;
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;

@RestController
@RequestMapping("/web/live")
public class WebLiveInformationController extends BaseLoginController {

    @Autowired
    private WebLiveInformationFeignService webLiveInformationFeignService;

    @Autowired
    private CommonService commonService;

    /**
     * 添加信息
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated WebLiveInformationAddEntity entity) throws Exception {

        return webLiveInformationFeignService.add(entity);
    }

    /**
     * 删除信息
     */
    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated WebLiveInformationDeleteEntity entity) throws Exception {

        return webLiveInformationFeignService.delete(entity);
    }

    /**
     * 修改信息
     */
    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated WebLiveInformationUpdateEntity entity) throws Exception {
        
        return webLiveInformationFeignService.update(entity);
    }
    
    @PostMapping("/search/list")
    public BaseResultDto list(@RequestBody @Validated WebLiveInformationSearchListEntity entity) throws Exception {
        return webLiveInformationFeignService.pageSearchList(entity);

    }

    @PostMapping("/search/single")
    public BaseResultDto single(@RequestBody @Validated SingleLongEntity entity) throws Exception {

        return webLiveInformationFeignService.single(entity);

    }

    @PostMapping("/upload")
    public BaseResultDto upload(@RequestParam(value = "file",required = false) MultipartFile file) throws Exception {
        String middlePath = "/web/live/Information";
        commonService.validated(file);
        String path = commonService.uploadFile(middlePath, file);

        return BaseResultDto.success(Constants.UPLOAD_SUCCESS, path);

    }
}
