<commit_before>import * as fromCozyClient from 'redux-cozy-client'
import { getAccount } from '../accounts'
import * as fromRunning from './running'

export const DOCTYPE = 'io.cozy.triggers'
const triggersCollectionKey = 'triggers'

const reducer = (state = {}, action) => {
  switch (action.type) {
    case 'LAUNCH_TRIGGER':
    case 'RECEIVE_NEW_DOCUMENT':
      return {
        ...state,
        running: fromRunning.reducer(state.running, action)
      }
    default:
      return state
  }
}

export default reducer

// CRUD action creators

export const fetchTriggers = () =>
  fromCozyClient.fetchTriggers(triggersCollectionKey, 'konnector')

export const createKonnectorTrigger = (
  konnector,
  account,
  folder,
  options = {}
) =>
  fromCozyClient.createTrigger(
    buildKonnectorTrigger(konnector, account, folder, options),
    {
      updateCollections: [triggersCollectionKey]
    }
  )

export const deleteTrigger = trigger =>
  fromCozyClient.deleteTrigger(trigger, {
    updateCollections: [triggersCollectionKey]
  })

export const launchTrigger = trigger => fromCozyClient.launchTrigger(trigger)

// Helpers
export const buildTriggerFrequencyOptions = (konnector, options) => {
  const { frequency } = konnector
  const { day, hours, minutes } = options

  const frequencyOptions = {
    frequency:
      frequency && ['weekly', 'daily'].includes(frequency)
        ? frequency
        : 'weekly'
  }

  if (frequencyOptions.frequency === 'daily') {
    return {
      ...frequencyOptions,
      hours,
      minutes
    }
  }

  // weekly case by default
  return {<commit_msg>feat: use constant for valid frequencies ✨<commit_after>import * as fromCozyClient from 'redux-cozy-client'
import { getAccount } from '../accounts'
import * as fromRunning from './running'

export const DOCTYPE = 'io.cozy.triggers'
const VALID_FREQUENCIES = ['weekly', 'daily']

const triggersCollectionKey = 'triggers'

const reducer = (state = {}, action) => {
  switch (action.type) {
    case 'LAUNCH_TRIGGER':
    case 'RECEIVE_NEW_DOCUMENT':
      return {
        ...state,
        running: fromRunning.reducer(state.running, action)
      }
    default:
      return state
  }
}

export default reducer

// CRUD action creators

export const fetchTriggers = () =>
  fromCozyClient.fetchTriggers(triggersCollectionKey, 'konnector')

export const createKonnectorTrigger = (
  konnector,
  account,
  folder,
  options = {}
) =>
  fromCozyClient.createTrigger(
    buildKonnectorTrigger(konnector, account, folder, options),
    {
      updateCollections: [triggersCollectionKey]
    }
  )

export const deleteTrigger = trigger =>
  fromCozyClient.deleteTrigger(trigger, {
    updateCollections: [triggersCollectionKey]
  })

export const launchTrigger = trigger => fromCozyClient.launchTrigger(trigger)

// Helpers
export const buildTriggerFrequencyOptions = (konnector, options) => {
  const { frequency } = konnector
  const { day, hours, minutes } = options

  const frequencyOptions = {
    frequency:
      frequency && VALID_FREQUENCIES.includes(frequency) ? frequency : 'weekly'
  }

  if (frequencyOptions.frequency === 'daily') {
    return {
      ...frequencyOptions,
      hours,
      minutes
    }
  }

  // weekly case by default
  return {
{'fraction_non_alphanumeric': 0.10869565217391304, 'fraction_numerical': 0.0, 'mean_word_length': 3.4753424657534246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3487810', 'n_tokens_mistral': 994, 'n_tokens_neox': 976, 'n_words': 229}