class Api::V1::Projects::ScaController < Api::V1::BaseController
  before_action :require_public_and_member_above
  before_action :load_project
  def index
    @result = Api::V1::Projects::Sca::ProjectShowService.call(@project)
  end
  def create
    result = Api::V1::Projects::Sca::CreateProjectService.call(@project)
    if result
      @result = Api::V1::Projects::Sca::ProjectShowService.call(@project)
    else
      {
        auth_token: nil,
        "url": nil,
      }
    end
    render :index
  end

  def scanner #创建扫描
    @result = Api::V1::Projects::Sca::ScannerService.call(@project, params[:branch])
    render :index
  end

  def scanner_list #扫描列表
    @result = Api::V1::Projects::Sca::ScannerListService.call(@project, params[:scan_type], params[:limit], params[:page])
    render :index
  end

  def scanner_show #扫描详情
    @result = Api::V1::Projects::Sca::ScannerShowService.call(params[:scan_id])
    render :index
  end

  def reports  #创建报告 ASC   SCA SAST
    @result = Api::V1::Projects::Sca::ReportService.call(params[:scan_type], params[:scan_id])
    render :index
  end

  def report_list #报告列表
    @result = Api::V1::Projects::Sca::ReportListService.call(params[:scan_id])
    render :index
  end

  def report_export #报告导出
    @result = Api::V1::Projects::Sca::ReportExportService.call(params[:scan_type], params[:scan_id])
    render :index
  end

  def dependency_tree
    @result = Api::V1::Projects::Sca::DependencyTreeService.call(params[:scan_id])
    render :index
  end

  def scan_issues
    @result = Api::V1::Projects::Sca::ScanIssuesService.call(params[:scan_id],params[:scan_library_id], params[:page], params[:limit])
    render :index
  end

  def scan_library
    @result = Api::V1::Projects::Sca::ScanLibraryService.call(params[:scan_id],params[:scan_library_id])
    render :index
  end
end