# List pull requests files
class Gitea::PullRequest::FilesService < Gitea::ClientService
  attr_reader :owner, :repo, :pull_number, :token, :params

  # GET /repos/{owner}/{repo}/pulls/{pull_number}/files
  # owner: 用户
  # repo: 仓库名称/标识
  # pull_number: pull request主键id
  # eg:
  # Gitea::PullRequest::FilesService.call('jasder', 'repo_identifier', 1)
  def initialize(owner, repo, pull_number, token=nil, params={})
    @owner  = owner
    @repo   = repo
    @token  = token
    @pull_number = pull_number
    @params = params
  end

  def call
    response = get(url, params.merge(token: token), true)
    render_result(response)
  end

  private
  # def params
  #   Hash.new.merge(token: token)
  # end
  
  def url
    "/repos/#{owner}/#{repo}/pulls/#{pull_number}/files".freeze
  end

  def render_result(response)
    case response.status
    when 200
      JSON.parse(response.body)
    else
      nil
    end
  end
end
