package com.crm.custom.controller;

import com.crm.custom.service.GoldenGoodsVideoService;
import com.crm.rely.backend.core.constant.Constants;
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.entity.base.SingleLongEntity;
import com.crm.rely.backend.model.dto.golden.goods.GoldenGoodsVideoListDto;
import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
import com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsVideoAddEntity;
import com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsVideoDeleteEntitys;
import com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsVideoSearchEntity;
import com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsVideoUpdateEntity;
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 javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/goods/video")
public class GoldenGoodsVideoController {

    @Autowired
    private GoldenGoodsVideoService goldenGoodsVideoService;

    @PostMapping("/search/list")
    public ResultWithPagerDto<GoldenGoodsVideoListDto> customPageList(@RequestBody GoldenGoodsVideoSearchEntity entity, CustomInfoEntity infoEntity) throws Exception {
        return goldenGoodsVideoService.customPageList(entity, infoEntity);
    }

    @PostMapping("/manager/add")
    @FeignClientAnnotation
    public BaseResultDto add(@RequestBody @Validated GoldenGoodsVideoAddEntity entity) throws Exception {
        goldenGoodsVideoService.add(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/manager/delete")
    @FeignClientAnnotation
    public BaseResultDto delete(@RequestBody @Validated GoldenGoodsVideoDeleteEntitys entitys) throws Exception {

        goldenGoodsVideoService.delete(entitys);
        return BaseResultDto.success();
    }

    @PostMapping("/manager/update")
    @FeignClientAnnotation
    public BaseResultDto update(@RequestBody @Validated GoldenGoodsVideoUpdateEntity entity) throws Exception {
        goldenGoodsVideoService.update(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/manager/search/list")
    @FeignClientAnnotation
    public ResultWithPagerDto<GoldenGoodsVideoListDto> pageList(@RequestBody GoldenGoodsVideoSearchEntity entity) throws Exception {
        return goldenGoodsVideoService.searchPageList(entity);
    }

    @PostMapping("/manager/search/single")
    @FeignClientAnnotation
    public BaseResultDto searchSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        return BaseResultDto.success(goldenGoodsVideoService.searchSingle(entity));
    }

    @PostMapping("/manager/upload/{goodsId}")
    @FeignClientAnnotation
    public BaseResultDto managerUpload(@RequestParam(value = "file", required = false) MultipartFile file,
                                       @PathVariable("goodsId") Long goodsId, HttpServletRequest req) throws Exception {

        //goldenGoodsVideoService.validatedVideo(file);

        String path = goldenGoodsVideoService.uploadFile(goodsId, file);
        return BaseResultDto.success(Constants.UPLOAD_SUCCESS, path);
    }

}
