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.WebLiveInstructorFeignService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.web.live.WebLiveInstructorDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.web.live.WebLiveInstructorAddEntity;
import com.crm.rely.backend.core.entity.web.live.WebLiveInstructorDeleteEntity;
import com.crm.rely.backend.core.entity.web.live.WebLiveInstructorSearchListEntity;
import com.crm.rely.backend.core.entity.web.live.WebLiveInstructorUpdateEntity;
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;

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

    @Autowired
    private WebLiveInstructorFeignService webLiveInstructorFeignService;

    @Autowired
    private CommonService commonService;

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

        return webLiveInstructorFeignService.add(entity);
    }

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

        return webLiveInstructorFeignService.delete(entity);
    }

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

    }

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

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

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

    }

    @PostMapping("/all/list")
    public BaseResultDto<List<WebLiveInstructorDto>> getAllList(@RequestBody WebLiveInstructorSearchListEntity entity) throws Exception {
        return webLiveInstructorFeignService.getAllList(entity);
    }

}
