package com.yonge.cooleshow.admin.controller.open;

import com.yonge.cooleshow.biz.dal.dto.MusicImgDto;
import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
import com.yonge.cooleshow.biz.dal.service.UserAccountService;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.cooleshow.common.entity.MallOrderItemDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.validation.Valid;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/open")
@Api(value = "开放权限接口", tags = "开放权限接口")
public class OpenUserAccountController extends BaseController {
    private final static Logger log = LoggerFactory.getLogger(OpenUserAccountController.class);



    @Autowired
    private UserAccountService userAccountService;

    @Autowired
    private MusicSheetService musicSheetService;

    /**
     * 设置商城收入分润
     */
    @PostMapping("/mallRecord")
    public HttpResponseResult<Boolean> mallRecord(@RequestBody List<MallOrderItemDto> shareDto ) {
        return succeed(userAccountService.saveMallAccountRecord(shareDto));
    }



    /**
     * 设置商城收入状态
     */
    @PostMapping("/mallRecordState")
    public HttpResponseResult<Boolean> mallRecordState(@RequestBody List<MallOrderItemDto> shareDto ) {
        userAccountService.mallTeacherRecordState(shareDto);
        return succeed();
    }



    @ApiOperation(value = "新增曲谱渲染图")
    @PostMapping(value="/music/sheet/img")
    public HttpResponseResult<Boolean> img(@RequestBody @Valid MusicImgDto musicImgDto) {
        return succeed(musicSheetService.updateMusicImg(musicImgDto, musicImgDto.getMusicSheetId()));
    }

    @ApiOperation(value = "曲目数据修复")
    @PostMapping(value="/music/sheet/musicCorrect")
    public HttpResponseResult<Boolean> musicCorrect(@RequestBody MusicImgDto musicImgDto) {
        if (Objects.isNull(musicImgDto.getMusicSheetId())) {
            failed("曲目Id参数错误");
        }
        return succeed(musicSheetService.updateMusicCorrect(musicImgDto, musicImgDto.getMusicSheetId()));
    }

}
