package frc.robot.subsystems;

import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.constants.TruckHornConstants;

public class TruckHorn extends SubsystemBase {
    private Relay horn;

    public TruckHorn() {
        horn = new Relay(TruckHornConstants.kTruckHornRelayChannel);
    }
    
    public Command blastHorn() {
        return run(() -> {
            horn.set(Relay.Value.kOn);
        });
    }

    public Command timedBlastHorn(double timeout) {
        return blastHorn().withTimeout(timeout);
    }

    public Command threeBlasts(double blastDuration, double timeoutDuration) {
        return timedBlastHorn(blastDuration).andThen(
            stop().withTimeout(timeoutDuration),
            timedBlastHorn(blastDuration),
            stop().withTimeout(timeoutDuration),
            timedBlastHorn(blastDuration)
        );
    }

    public Command stop() {
        return run(() -> {
            horn.set(Relay.Value.kOff);
        });
    }
}
