/*
 * Copyright (c) 2024 Titan Robotics Club (http://www.titanrobotics.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package teamcode.subsystems;

import ftclib.driverio.FtcGamepad;
import ftclib.driverio.FtcGamepadRumble;
import trclib.driverio.TrcPriorityIndicator;

/**
 * This class encapsulates the gamepad rumble to provide a priority indicator showing the status of the robot.
 */
public class RumbleIndicator
{
    // Rumble pattern names.
    public static final String ENDGAME_DEADLINE = "EndGameDeadline";
    private final TrcPriorityIndicator<?> indicator;

    /**
     * Constructor: Create an instance of the object.
     *
     * @param indicatorName specifies the indicator hardware name.
     * @param gamepad specifies the gamepad to use for the rumble.
     */
    public RumbleIndicator(String indicatorName, FtcGamepad gamepad)
    {
        final FtcGamepadRumble.Pattern[] rumblePatternPriorities = {
            // Highest priority.
            new FtcGamepadRumble.Pattern(ENDGAME_DEADLINE, 3)
            // Lowest priority.
        };
        indicator = new FtcGamepadRumble(indicatorName, gamepad.gamepad);
        ((FtcGamepadRumble) indicator).setPatternPriorities(rumblePatternPriorities);
    }   //RumbleIndicator

    /**
     * This method sets the rumble pattern ON for a period of time and turns off automatically afterwards.
     *
     * @param patternName specifies the name of the rumble pattern to turn on.
     */
    public void setRumblePattern(String patternName)
    {
        if (indicator != null)
        {
            indicator.setPatternState(patternName, true, 1.0);
        }
    }   //setRumblePattern

}   //class RumbleIndicator
