package com.yonge.cooleshow.biz.dal.service.cbs.impl;

import com.alibaba.fastjson.JSONObject;
import com.dayaedu.cbs.openfeign.client.MusicFeignClientService;
import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetApplicationExtendClientWrapper;
import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetWrapper;
import com.microsvc.toolkit.common.response.paging.PageInfo;
import com.microsvc.toolkit.common.response.template.R;
import com.yonge.cooleshow.biz.dal.service.cbs.CbsMusicScoreService;
import com.yonge.toolset.base.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class CbsMusicScoreServiceImpl implements CbsMusicScoreService {

    @Value("${openfeign-client.app-id:1745637981387108354}")
    public Long applicationId;
    @Resource
    private MusicFeignClientService musicFeignClientService;

    @Override
    public R<PageInfo<CbsMusicSheetWrapper.MusicSheetApplication>> selectPage(CbsMusicSheetWrapper.MusicSheetApplicationQuery query) {
        query.setApplicationId(applicationId);
        return musicFeignClientService.musicSheetPageByApplication(query);
    }

    @Override
    public void update(CbsMusicSheetApplicationExtendClientWrapper.AddMusicSheetApplicationExtend addMusicSheetApplicationExtend) {
        addMusicSheetApplicationExtend.setApplicationId(applicationId);
        R<JSONObject> jsonObjectR = musicFeignClientService.musicSheetApplicationExtendUpdate(addMusicSheetApplicationExtend);
        if (jsonObjectR.getCode() != 200) {
            throw new BizException("修改失败,{}",jsonObjectR.getMessage());
        }
    }

    @Override
    public void updateStatus(CbsMusicSheetApplicationExtendClientWrapper.MusicSheetApplicationExtendStatus status) {
        R<JSONObject> jsonObjectR = musicFeignClientService.musicSheetApplicationExtendStatus(status);
        if (jsonObjectR.getCode() != 200) {
            throw new BizException("修改状态失败,{}",jsonObjectR.getMessage());
        }
    }

    @Override
    public R<CbsMusicSheetWrapper.MusicSheet> musicSheetDetail(Long id) {
        return musicFeignClientService.musicSheetDetail(id, applicationId);
    }
}
