class Reposync::CreateSyncRepoService < Reposync::ClientService

  attr_accessor :repo_name, :internal_repo_address, :inter_token, :external_repo_address, :exter_token, :sync_granularity, :sync_direction, :enable

  def initialize(repo_name, internal_repo_address, inter_token, external_repo_address, exter_token, sync_granularity, sync_direction, enable=true)
    @repo_name = repo_name
    @internal_repo_address = internal_repo_address
    @inter_token = inter_token
    @external_repo_address = external_repo_address
    @exter_token = exter_token
    @sync_granularity = sync_granularity
    @sync_direction = sync_direction
    @enable = enable
  end

  def call 
    result = post(url, request_params)
    response = render_response(result)
  end

  private 
  def request_params
    Hash.new.merge(data: {
      repo_name: repo_name,
      enable: enable,
      internal_repo_address: internal_repo_address,
      inter_token: inter_token,
      external_repo_address: external_repo_address,
      exter_token: exter_token,
      sync_granularity: sync_granularity,
      sync_direction: sync_direction
    }.stringify_keys)
  end

  def url 
    "/cerobot/sync/repo".freeze
  end
end