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

  attr_accessor :project, :token, :owner, :repo, :page, :limit
  attr_accessor :gitea_data

  def initialize(project, params, token=nil)
    @project = project 
    @owner = project&.owner.login 
    @repo = project&.identifier 
    @token = token 
    @page = params[:page] 
    @limit = params[:limit]
  end

  def call 
    load_gitea_data
    
    gitea_data
  end

  private 
  def request_params 
    params = {
      access_token: token,
      page: page, 
      limit: limit
    }

    params
  end

  def load_gitea_data 
    @gitea_data = $gitea_hat_client.get_repos_tags_by_owner_repo(owner, repo, {query: request_params}) rescue nil
    raise Error, '获取标签列表失败！' unless @gitea_data.is_a?(Hash)
  end
end