class Api::V1::Projects::Webhooks::ListService < ApplicationService

  attr_reader :project, :token, :owner, :repo
  attr_accessor :gitea_data

  def initialize(project, token=nil)
    @project = project
    @owner = project&.owner.login 
    @repo = project&.identifier
    @token = token
  end

  def call 
    load_gitea_data

    gitea_data
  rescue 
    raise Error, "服务器错误，请联系系统管理员！"
  end

  private 
  def request_params 
    {
      access_token: token
    }
  end

  def load_gitea_data 
    @gitea_data = $gitea_client.get_repos_hooks_by_owner_repo(owner, repo, {query: request_params}) rescue nil
  end
end