package com.izouma.wenlvju.service.performance;

import com.izouma.wenlvju.domain.performance.Performance;
import com.izouma.wenlvju.dto.PageQuery;
import com.izouma.wenlvju.enums.PerformanceStatus;
import com.izouma.wenlvju.exception.BusinessException;
import com.izouma.wenlvju.repo.performance.PerformanceRepo;
import com.izouma.wenlvju.utils.JpaUtils;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
@AllArgsConstructor
public class PerformanceService {

    private PerformanceRepo performanceRepo;

    public Page<Performance> all(PageQuery pageQuery) {
        return performanceRepo.findAll(JpaUtils.toSpecification(pageQuery, Performance.class), JpaUtils.toPageRequest(pageQuery));
    }

    /*
    设置复审比例
     */
    public Performance settingUpReview(Long id, BigDecimal ratio, boolean online) {
        Performance performance = performanceRepo.findById(id).orElseThrow(new BusinessException("无展演"));
        performance.setStatus(PerformanceStatus.ARRANGE);
        performance.setAuditTimes(2);
        performance.setReviewRatio(ratio);
        performance.setReviewOnline(online);
        return performanceRepo.save(performance);
    }
}
