module Croup
  class S3Config
    attr_reader :params

    def initialize(settings = {})
      @params = {}
      settings.each_pair {|k, v| send("#{k}=", v) }
    end

    def access_key_id=(id)
      @params['accessKeyId'] = id
    end

    def access_key_secret=(secret)
      @params['secretAccessKey'] = secret
    end

    def pool_id=(id)
      @params['IdentityPoolId'] = id
    end

    # {
    #   'graph.facebook.com': 'FBTOKEN',
    #   'www.amazon.com': 'AMAZONTOKEN',
    #   'accounts.google.com': 'GOOGLETOKEN'
    # }
    def logins=(logins_hash)
      @params['Logins'] = logins_hash
    end


    def acl=(file_permission)
      @params['acl'] = file_permission
    end

    def bucket=(name)
      @params['bucket'] = name
    end

    def region=(region)
      @params['region'] = region
    end

    def path=(path)
      @params['path'] = path
    end

    def generate_unique_name=(generate)
      @params['generateUniqueName'] = generate
    end

    def to_json(other_config = nil)
      @params.reverse_merge(other_config ? other_config.params : {}).to_json
    end
  end
end