class Gitea::Repository::ActionSecretsService < Gitea::ClientService
  attr_reader :owner, :repo, :secret_name, :secret

  def initialize(owner, repo, secret_name, secret)
    @owner   = owner
    @repo    = repo
    @secret_name = secret_name
    @secret = secret
  end

  def call
    response = put(url, request_params)
    render_201_response(response)
  end

  def destroy
    response = delete(url, request_params)
    render_201_response(response)
  end


  private

  def request_params
    Hash.new.merge(token: owner.gitea_token, data: { data: secret } )
  end



  def url
    "/repos/#{owner.login}/#{repo}/actions/secrets/#{secret_name}".freeze
  end
end
