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

import com.alibaba.fastjson.JSONObject;
import com.dayaedu.cbs.common.enums.music.EMusicAvailableType;
import com.dayaedu.cbs.openfeign.client.MusicFeignClientService;
import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetApplicationExtendClientWrapper;
import com.microsvc.toolkit.common.response.template.R;
import com.yonge.cooleshow.biz.dal.service.cbs.CbsMusicScoreService;
import com.yonge.cooleshow.biz.dal.wrapper.MusicSheetApplicationExtendWrapper;
import com.yonge.toolset.base.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
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 void update(MusicSheetApplicationExtendWrapper addMusicSheetApplicationExtend) {
        CbsMusicSheetApplicationExtendClientWrapper.AddMusicSheetApplicationExtend extend =
                JSONObject.parseObject(JSONObject.toJSONString(addMusicSheetApplicationExtend), CbsMusicSheetApplicationExtendClientWrapper.AddMusicSheetApplicationExtend.class);
        extend.setApplicationId(applicationId);
        if(StringUtils.isNotEmpty(addMusicSheetApplicationExtend.getAvailableType())){
            extend.setAvailableType(StringUtils.equals(addMusicSheetApplicationExtend.getAvailableType(),"PLATFORM") ? EMusicAvailableType.PLATFORM : EMusicAvailableType.ORG);
        }
        R<JSONObject> jsonObjectR = musicFeignClientService.musicSheetApplicationExtendUpdate(extend);
        if (jsonObjectR.getCode() != 200) {
            throw new BizException("修改失败,{}",jsonObjectR.getMessage());
        }
    }
}
