# 代码溯源 开始检测
class Trace::CheckService < Trace::ClientService

  attr_accessor :token, :project, :if_branch, :branch_tag 

  def initialize(token, project, if_branch, branch_tag) 
    @token = token 
    @project = project 
    @if_branch = if_branch
    @branch_tag = branch_tag
  end

  def call
    result = authed_post(token, url, {data: request_params})
    reponse = render_response(result)
  end

  private 
  def request_params 
   repo = Gitea::Repository::GetService.call(project&.owner&.login, project&.identifier)
    {
      product_name: project&.name, 
      product_type: project&.category&.name,
      code_type: project&.language&.name,
      product_desc: project&.description,
      git_url: repo['clone_url'],
      if_branch: if_branch,
      branch_tag: branch_tag
    }
  end

  def url 
    "/user/check".freeze
  end
end

