<commit_before>//
//  SynonymsSnippets.swift
//  
//
//  Created by <NAME> on 29/06/2020.
//

import Foundation
import AlgoliaSearchClient

struct SynonymsSnippets: SnippetsCollection {}

//MARK: - Save synonym
extension SynonymsSnippets {
  
  static var saveSynonym: String = """
  index.saveSynonym(
    _ #{synonym}: __Synonym__,
    #{forwardToReplicas}: __Bool?__ = nil,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<SynonymRevision> -> Void__
  )
  """
  
  func saveRegular() {
    let synonym: Synonym = .multiWay(objectID: "myID",
                                     synonyms: ["car", "vehicle", "auto"])
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
  func saveOneWay() {
    let synonym: Synonym = .oneWay(objectID: "myID",
                                   input: "car",
                                   synonyms: ["vehicle", "auto"])
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
  func saveAltCorr1() {
    let synonym: Synonym = .alternativeCorrection(objectID: "myID",
                                                  word: "car",
                                                  corrections: ["vehicle", "auto"],
                                                  typo: .one)
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
  func saveAltCoor2() {
    let synonym: Synonym = .alternativeCorrection(objectID: "myID",
                                                  word: "car",
                                                  corrections: ["vehicle", "auto"],
                                                  typo: .two)
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
  func savePlaceholder() {
    let synonym: Synonym = .placeholder(objectID: "myID",
                                        placeholder: "street",
                                        replacements: ["street", "st"])
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Batch synonyms

extension SynonymsSnippets {
  
  static var saveSynonyms: String = """
  index.saveSynonyms(
    _ #{synonyms}: __[Synonym]__,
    #{forwardToReplicas}: __Bool?__ = nil,
    #{replaceExistingSynonyms}: __Bool?__ = nil,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<IndexRevision> -> Void__
  )
  """
  
  func saveSynonyms() {
    let synonyms: [Synonym] = [
      .multiWay(objectID: "myID1", synonyms: ["car", "vehicle", "auto"]),
      .multiWay(objectID: "myID2", synonyms: ["street", "st"])
    ]
    
    index.saveSynonyms(synonyms, forwardToReplicas: true, replaceExistingSynonyms: false) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Delete synonym

extension SynonymsSnippets {
  
  static var deleteSynonym = """
  index.deleteSynonym(
    withID #{objectID}: __ObjectID__,
    #{forwardToReplicas}: __Bool?__ = nil,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<IndexDeletion> -> Void__
  )
  """
  
  func deleteSynonym() {
    // Delete and forward to replicas
    index.deleteSynonym(withID: "myID", forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Clear synonyms

extension SynonymsSnippets {
  
  static var clearSynonyms = """
  index.clearSynonyms(
    #{forwardToReplicas}: __Bool?__ = nil,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<IndexRevision> -> Void__
  )
  """
  
  func clearSynonyms() {
    index.clearSynonyms(forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Get synonym

extension SynonymsSnippets {
  
  static var getSynonym = """
  index.getSynonym(
    withID #{objectID}: __ObjectID__,
    requestOptions: __RequestOptions?__ = nil,
    completion: __ResultCallback<Synonym>__
  )
  """
  
  func getSynonym() {
    index.getSynonym(withID: "myID") { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Search synonyms

extension SynonymsSnippets {
  
  static var searchSynonyms = """
    index.searchSynonyms(
      _ query: __SynonymQuery_,
      requestOptions: __RequestOptions?__ = nil,
      completion: __SynonymSearchResponse -> Void__
    )

    struct SynonymQuery {
      var #{query}: __String?__ = nil
      var #{page}: __Int?__ = nil
      var #{hitsPerPage}: __Int?__ = nil
      var [synonymTypes](#method-param-type): __[SynonymType]?__ = nil
    }<commit_msg>Fix get synonym completion type in snippet<commit_after>//
//  SynonymsSnippets.swift
//  
//
//  Created by <NAME> on 29/06/2020.
//

import Foundation
import AlgoliaSearchClient

struct SynonymsSnippets: SnippetsCollection {}

//MARK: - Save synonym
extension SynonymsSnippets {
  
  static var saveSynonym: String = """
  index.saveSynonym(
    _ #{synonym}: __Synonym__,
    #{forwardToReplicas}: __Bool?__ = nil,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<SynonymRevision> -> Void__
  )
  """
  
  func saveRegular() {
    let synonym: Synonym = .multiWay(objectID: "myID",
                                     synonyms: ["car", "vehicle", "auto"])
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
  func saveOneWay() {
    let synonym: Synonym = .oneWay(objectID: "myID",
                                   input: "car",
                                   synonyms: ["vehicle", "auto"])
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
  func saveAltCorr1() {
    let synonym: Synonym = .alternativeCorrection(objectID: "myID",
                                                  word: "car",
                                                  corrections: ["vehicle", "auto"],
                                                  typo: .one)
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
  func saveAltCoor2() {
    let synonym: Synonym = .alternativeCorrection(objectID: "myID",
                                                  word: "car",
                                                  corrections: ["vehicle", "auto"],
                                                  typo: .two)
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
  func savePlaceholder() {
    let synonym: Synonym = .placeholder(objectID: "myID",
                                        placeholder: "street",
                                        replacements: ["street", "st"])
    
    index.saveSynonym(synonym, forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Batch synonyms

extension SynonymsSnippets {
  
  static var saveSynonyms: String = """
  index.saveSynonyms(
    _ #{synonyms}: __[Synonym]__,
    #{forwardToReplicas}: __Bool?__ = nil,
    #{replaceExistingSynonyms}: __Bool?__ = nil,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<IndexRevision> -> Void__
  )
  """
  
  func saveSynonyms() {
    let synonyms: [Synonym] = [
      .multiWay(objectID: "myID1", synonyms: ["car", "vehicle", "auto"]),
      .multiWay(objectID: "myID2", synonyms: ["street", "st"])
    ]
    
    index.saveSynonyms(synonyms, forwardToReplicas: true, replaceExistingSynonyms: false) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Delete synonym

extension SynonymsSnippets {
  
  static var deleteSynonym = """
  index.deleteSynonym(
    withID #{objectID}: __ObjectID__,
    #{forwardToReplicas}: __Bool?__ = nil,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<IndexDeletion> -> Void__
  )
  """
  
  func deleteSynonym() {
    // Delete and forward to replicas
    index.deleteSynonym(withID: "myID", forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Clear synonyms

extension SynonymsSnippets {
  
  static var clearSynonyms = """
  index.clearSynonyms(
    #{forwardToReplicas}: __Bool?__ = nil,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<IndexRevision> -> Void__
  )
  """
  
  func clearSynonyms() {
    index.clearSynonyms(forwardToReplicas: true) { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Get synonym

extension SynonymsSnippets {
  
  static var getSynonym = """
  index.getSynonym(
    withID #{objectID}: __ObjectID__,
    requestOptions: __RequestOptions?__ = nil,
    completion: __Result<Synonym> -> Void__
  )
  """
  
  func getSynonym() {
    index.getSynonym(withID: "myID") { result in
      if case .success(let response) = result {
        print("Response: \(response)")
      }
    }
  }
  
}

//MARK: - Search synonyms

extension SynonymsSnippets {
  
  static var searchSynonyms = """
    index.searchSynonyms(
      _ query: __SynonymQuery_,
      requestOptions: __RequestOptions?__ = nil,
      completion: __SynonymSearchResponse -> Void__
    )

    struct SynonymQuery {
      var #{query}: __String?__ = nil
      var #{page}: __Int?__ = nil
      var #{hitsPerPage}: __Int?__ = nil
      var [synonymTypes](#method-param-type): __[SynonymType]?__ = nil
    }
{'fraction_non_alphanumeric': 0.12148736871984105, 'fraction_numerical': 0.0022707919386886176, 'mean_word_length': 2.138361045130641, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2142816', 'n_tokens_mistral': 3375, 'n_tokens_neox': 3217, 'n_words': 705}