import os

from os.path import abspath, dirname, join

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = dirname(dirname(abspath(__file__)))

# duration of the fade out at the end of a playlist in second
FADE_OUT_DURATION = 20

# number of step during the fade out.
# At each step, the volume is reduced by the same amount until 0
FADE_OUT_STEP = 50

BO_API_URL = 'https://owlright.hashbang.fr'
API_BASIC_USERNAME = 'apimaster@owlright.fr'
API_BASIC_PASSWORD = '>Mast3r of the AP1s<'
ADMIN_TOKEN = '870ADM1N990WLRIGHT43'

# expects output like : "KeyName       : value"
SERIAL_NUMBER_READ_COMMAND = 'cat /proc/cpuinfo | grep Serial'

CONFIG_FILE_PATH = join(BASE_DIR, 'var', 'owltail.conf')
DEFAULT_SONGS_FOLDER = join(BASE_DIR, 'var', "songs")

SERIAL_NUMBER_READ_COMMAND = 'cat /proc/cpuinfo | grep microcode | head -n 1'


if os.environ.get('OWLTAIL_ENV') == 'production':
    CONFIG_FILE_PATH = '/var/lib/owltail/owltail.conf'
    DEFAULT_SONGS_FOLDER = "/var/lib/owltail/songs"

    VOLUME_INDEXES = [0, 2]
    LOW_INDEX = 1

    PLAYER_RPI_IDX = 1
    PLAYER_LINEIN_IDX = 0

    PLAYER_WRITE_MUX_CMD = '/var/lib/owltail/firmware/spi_write_mux'
    PLAYER_SET_GAIN_CMD = '/var/lib/owltail/firmware/spi_write_gain'
    PLAYER_SET_FILTER_CMD = '/var/lib/owltail/firmware/spi_write_filter'
    WRITE_DSP_CMD = '/var/lib/owltail/firmware/spi_write_program'

    PLAYER_SOFT_VOLUME = 40  # volume avant carte son, pourcentage
    PLAYER_VOLUME_MAX = 10  # volume de la carte son, pourcentage
    PLAYER_VOLUME_START = 20  # volume de depart global, pourcentage
    PLAYER_LOW_START = 20
    PLAYER_FILTER_START = 20

    FILTER_MAX = 250
    FILTER_MIN = 20
