class Api::V1::Projects::Git::BlobsService < ApplicationService 
  include ActiveModel::Model

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

  validates :sha, presence: :true


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

  def call 
    load_gitea_data 

    gitea_data
  end

  private 
  def request_params 
    {
      access_token: token
    }
  end

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